I Need Some Help Promises And Q Library
I need some help on syntax with node.js promises. In readme for node.js module called q https://github.com/kriskowal/q is written something I don't understand. Why do they always w
Solution 1:
The reason is that in that case they want to return the promise to the caller of the current function.
I've done this in my own program and it is done thus:
- First note that the second argument of
Q.ncall([function], [this], [arguments,...])
isthis
. Secondly note that the arguments to the callback given by
Q.ncall
to the given function are the same as all other node.js callbacks(error, result)
thus the need to give the callbacknull
as the error on success.var Q = require('q'); functiondoThis(a,b, callback) { var result = a + b; setTimeout(function () { callback(null, result) }, 2000); } Q.ncall(doThis, null, 2, 3).then(function(result) { console.error(result); });
This code works as you describe; note the differences.
- First note that the second argument of
Post a Comment for "I Need Some Help Promises And Q Library"