Skip to content

Instantly share code, notes, and snippets.

@tj
Last active December 17, 2015 05:39
Show Gist options
  • Select an option

  • Save tj/5559094 to your computer and use it in GitHub Desktop.

Select an option

Save tj/5559094 to your computer and use it in GitHub Desktop.
var thread = require('./');
var join = thread.join;
var redis = require('redis');
var db = redis.createClient();
function get(key) {
return function(done){
db.get(key, done);
}
}
function set(key, val) {
return function(done){
db.set(key, val, done);
}
}
thread(function *(){
yield set('tobi:name', 'tobi')
yield set('tobi:species', 'ferret')
yield set('tobi:age', 3)
// serial
var name = yield get('tobi:name')
var species = yield get('tobi:species')
var age = yield get('tobi:age')
console.log(name, species, age)
// parallel
var ret = yield join(
get('tobi:name'),
get('tobi:species'),
get('tobi:age')
)
console.log(ret[0], ret[1], ret[2]);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment