Utiliser yield pour faire un sleep()

<script type="text/javascript;version=1.7">
function what() {
    document.body.innerHTML = 'wait 1s...';
    yield 1000;
    document.body.innerHTML = 'wait more...';
    yield 2000;
    document.body.innerHTML = 'can you wait 3s please?';
    yield 3000;
    document.body.innerHTML = 'thank you';
}
    
function sleep(c) {
    var gen = c();
    var f = function() {
        try {
            var wait = gen.next();
            if(wait) {
                setTimeout(f, wait);
            }
        } catch(e) {
        }
    }
    f();
}
sleep(what);
</script>