function fetchData() { return function (callback) { setTimeout(() => { console.log('cb'); callback(null, 'fetchData'); }, 3000); };}
function secondAsyncTask() { return function (callback) { callback(null, 'secondAsyncTask'); };}
function thirdAsyncTask() { return function (callback) { callback(null, 'thirdAsyncTask'); };}
function* taskDef() { let result = yield fetchData(); result = yield secondAsyncTask(); result = yield thirdAsyncTask();}
function run(taskDef) { let task = taskDef(); let result = task.next();
function step() { if (!result.done) { if (typeof result.value === 'function') { function callback(error, data) { if (error) { result = task.throw(error); return; } result = task.next(data); } result.value(callback); } else { result = task.next(result.value); } step(); } }
step();}
run(taskDef);
So my question is how to really simulate some time delay, otherwise this. example will not work with async tasks, TIA.
--
You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zakasbooks/3021e436-0b87-41a2-953c-0a9fd40ea30f%40googlegroups.com.
Yes, you won’t be able to use this example with a timeout without some modification.I’d recommend instead that you use async functions (not covered in the book). There’s really no need to use generators for this purpose now that async functions exist.
On Sat, Apr 25, 2020 at 7:25 PM Jeff <zhenzh...@gmail.com> wrote:
So my question is how to really simulate some time delay, otherwise this. example will not work with async tasks, TIA.--
You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakas...@googlegroups.com.