I wrote a small generator that simply lists a bunch of messages that I passed to him:
'use strict';
const sequential = function * (messages) {
for (let i = 0; i < messages.length; i++) {
yield messages[i];
}
};
module.exports = sequential;
I use it as follows:
for (const message of sequential(messages)) {
}
Basically, everything is working fine. Now I want the generator to delay calls yield
, for example. for 100 milliseconds.
The problem is that I cannot just enter a call setTimeout
, because otherwise it is yield
no longer contained in the generator function, but a regular callback.
How can i solve this?
source
share