npm.io
1.0.6 • Published 12 years ago

vz.resolve

Licence
LGPL-3.0
Version
1.0.6
Deps
2
Vulns
0
Weekly
0

vz resolve

DEPRECATED in favour of vz.yielded

NPM

No piece of software is ever completed, feel free to contribute and be humble

Sample usage:


var resolve = require('vz.resolve'),
    nextTick = require('vz.next-tick'),
    result;

result = resolve(function solve(){
  if(Math.random() < 0.5) this.resolve('Hello world');
  else nextTick(solve,[],this);
},function(data){
  console.log('Received asynchronously:',data);
});

if(result != resolve.deferred) console.log('Received synchronously:',result);

Reference

resolve(function[,arguments],callback[,thisArg])

This function executes function with arguments or an empty array as arguments, and a new Resolver as the thisArg. If Resolver.resolve is called within function, then this function returns the value passed to that call, otherwise it returns resolve.deferred, a unique object representing that the task could not be completed synchronously, and executes callback with thisArg as thisArg when Resolver.resolve is called.