You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
io.Lazy allows handlers to have more control on asynchronous flow.
yield an io.Lazy in an handler allow to get promise instead of value, this promise must be yield to be resolved.
e.g.
const{ io, handler }=require('handle-io');constsleep=io(ms=>newPromise(resolve=>setTimeout(resolve,ms)));constmyHandler=handler(function*(){constsleepPromise1=yieldio.Lazy(sleep(1000));constsleepPromise2=yieldio.Lazy(sleep(2000));constsleepPromise3=yieldio.Lazy(sleep(3000));// at this point, all sleep IOs are ran in parallelyieldsleepPromise1;// waiting for first sleepyieldsleepPromise2;// waiting for second sleepyieldsleepPromise3;// waiting for third sleep});
The important point to note here is that yield sleep(1000) is blocking while yield io.lazy(sleep(1000)) is non-blocking.
Non-blocking asynchronous flow
io.Lazy
allows handlers to have more control on asynchronous flow.yield an
io.Lazy
in an handler allow to get promise instead of value, this promise must be yield to be resolved.e.g.
The important point to note here is that
yield sleep(1000)
is blocking whileyield io.lazy(sleep(1000))
is non-blocking.Related to #138.
The text was updated successfully, but these errors were encountered: