continuable-generators

Experimental usage of generators for continuables

continuable-generators

Experimental usage of generators for continuables

run takes a generator and returns a continuable. It's expected that the values you yield are continuables themself.

// run this with --harmony on node v0.11.2 
var Redis = require("redis")
var console = require("console")
var list = require("continuable-list")
var of = require("continuable/of")
 
var client = Redis.createClient()
var run = require("../index")
 
run(function*() {
    yield client.hmset.bind(client, "blog::post", {
        date: "20130605",
        title: "g3n3rat0rs r0ck",
        tags: "js,node"
    })
 
    var post = yield client.hgetall.bind(client, "blog::post")
    var tags = post.tags.split(",")
    var taggedPosts = yield list(tags.map(function (tag) {
        return client.hgetall.bind(client, "post::tag::" + tag)
    }))
 
    return of({ post: post, taggedPosts: taggedPosts })
})(function (errresult) {
    if (err) {
        throw err
    }
 
    console.log("post", result.post, "taggedPosts", result.taggedPosts)
 
    client.quit()
})

npm install continuable-generators

  • Raynos