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

Leading or trailing thunks #84

Closed
plievone opened this issue Feb 1, 2014 · 1 comment · Fixed by #104
Closed

Leading or trailing thunks #84

plievone opened this issue Feb 1, 2014 · 1 comment · Fixed by #104

Comments

@plievone
Copy link
Contributor

plievone commented Feb 1, 2014

It might clarify Readme.md examples if the difference between two kinds of thunks would be made clearer. Currently the thunks are introduced as trailing kind:

function read(...args) {
  return function thunk(cb) {
    // start work, cb(err, result) later
  }
}

but functions from thunkify start the work already on the leading edge:

function read(...args) {
  // start work, save result later
  return function thunk(cb) {
    // cb(err, result) or when result ready
  }
}

This difference helps to understand when work can start concurrently (in the event loop sense) even before yielding.

Currently the frontpage examples mix both styles, confusing where the concurrency comes in each case. And the example with "3 concurrent requests at a time" and "9 concurrent requests" won't do what it says, because there are those sequential yields in the *results() generator, whatever style the thunks are.

@navaru
Copy link
Contributor

navaru commented Mar 21, 2014

It think this is an implementation detail in thunkify, a thunk could be expressed the same, but in the case of thunkify, it's more like an optimization, in some cases by the time the generator calls .next() the asynchronous function may be done.

plievone pushed a commit to plievone/co that referenced this issue Mar 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants