I seems to not understand a simple thing: how to return a value from a function invoked in a fiber? I have almost readme example:
var Sync = require('sync');
function asyncFunction(a, b, callback) {
process.nextTick(function(){
callback(null, a + b);
})
}
var result = Sync(function(){
var result = asyncFunction.sync(null, 2, 3);
return result;
});
console.log(result)
and this does not work.
That API seemed quite obvioud for me, as far there is an intuition in the readme:
// Or simply specify callback function for Sync fiber
// handy when you use Sync in asynchronous environment
Sync(function(){
// The result will be passed to a Sync callback
var result = asyncFunction.sync(null, 2, 3);
return result;
}, function(err, result){ // <-- standard callback
if (err) console.error(err); // something went wrong
// The result which was returned from Sync body function
console.log(result);
})
So how it is possible to do so to return value?
I tried to write result to "outer scope" and it didn’t work.
Is there a way to pass any value back from sync call at all?
Hi @ybogdanov !
I seems to not understand a simple thing: how to return a value from a function invoked in a fiber? I have almost readme example:
and this does not work. That API seemed quite obvioud for me, as far there is an intuition in the readme:
So how it is possible to do so to return value?
I tried to write result to "outer scope" and it didn’t work. Is there a way to pass any value back from sync call at all?
Thanks.