Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add io.Lazy #139

Open
guillaumearm opened this issue Mar 29, 2018 · 0 comments
Open

add io.Lazy #139

guillaumearm opened this issue Mar 29, 2018 · 0 comments
Assignees
Labels
feat This is about feature

Comments

@guillaumearm
Copy link
Owner

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.

const { io, handler } = require('handle-io');

const sleep = io(ms => new Promise(resolve => setTimeout(resolve, ms)));

const myHandler = handler(function*() {
  const sleepPromise1 = yield io.Lazy(sleep(1000));
  const sleepPromise2 = yield io.Lazy(sleep(2000));
  const sleepPromise3 = yield io.Lazy(sleep(3000));

  // at this point, all sleep IOs are ran in parallel

  yield sleepPromise1; // waiting for first sleep
  yield sleepPromise2; // waiting for second sleep
  yield sleepPromise3; // 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.


Related to #138.

@guillaumearm guillaumearm added the feat This is about feature label Mar 29, 2018
@guillaumearm guillaumearm self-assigned this Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat This is about feature
Projects
None yet
Development

No branches or pull requests

1 participant