1.0.2 • Published 10 years ago

ycatch v1.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
10 years ago

ycatch

npm.io

npm.io

npm.io

Probably useless until node has destructuring assignment. It can be used without it though.

api

var read = intercept(thunk(fs.readFile));
var a = read('index.js', 'utf8');
var c = read('package.json', 'utf8');

var [[erra, a], [errb, b]] = yield [a, b];
if(erra) throw erra;
if(errb) throw errb;
assert(a.indexOf('exports') > 0)
assert(b.indexOf('devDependencies') > 0)
function sleep(ms) {
  return function(done){
    setTimeout(done, ms);
  };
}

var work = intercept(function *(){
  yield sleep(50);
  return 'yay';
});

var [, a] = yield work;
assert('yay' === a);
var [, b] = yield work;
assert('yay' === b);
var [, c] = yield work;
assert('yay' === c);

var [[, a], [, b], [, c]] = yield [work, work, work];
assert('yay' === a);
assert('yay' === b);
assert('yay' === c);