Skip to content

Conversation

mstdokumaci
Copy link

Sometimes an async function needs tor return a sync result. For the sake of consistency of async flow; we need to call the callback function wrapped in a nextTick block. This new method simplifys this effort.

Example:

function asyncFn (other_arguments, callback) {
  if (cached_result) {
    return async.callbackNextTick(callback, cached_result);
  }
  some_async_call(some_arguments, callback);
}

Sometimes an async function needs tor return  a sync result. For the sake of consistency of async flow; we need to call the callback function wrapped in a nextTick block. This new method simplifys this effort.

Example:
```js
function asyncFn (other_arguments, callback) {
  if (cached_result) {
    return async.callbackNextTick(callback, cached_result);
  }
  some_async_call(some_arguments, callback);
}
```
@aearly
Copy link
Collaborator

aearly commented May 7, 2015

So this is like async.nextTick, except you can pass additional parameters to the function?

What about augmenting async.nextTick and async.setImmediate to do that?

@aearly
Copy link
Collaborator

aearly commented May 7, 2015

Ah, this type of behavior was voted down in iojs: nodejs/node#1077

You can also accomplish the same thing by doing:

async.nextTick(callback.bind(null, cached_result));

@aearly aearly added the feature label May 21, 2015
@aearly
Copy link
Collaborator

aearly commented Jun 2, 2015

Well, looks like this was actually added: nodejs/node@10e31ba

@aearly
Copy link
Collaborator

aearly commented Oct 25, 2015

Closing, we'll track this in #940.

@aearly aearly closed this Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants