Last active
December 17, 2015 05:39
-
-
Save tj/5559094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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