Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gens with all npm packages installed. Try it out:

var gens = require("gens")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gens v1.1.0

Experimental usage of generators for continuables

gens

build status NPM version dependency status

Experimental usage of generators for continuables

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

Example

// run this with --use-strict --harmony on node v0.11.3
let Redis = require("redis")
let console = require("console")
let async = require("gens")
let parallel = require("gens/parallel")

let client = Redis.createClient()

async(function* () {
    yield client.hmset.bind(client, "blog::post", {
        date: "20130605",
        title: "g3n3rat0rs r0ck",
        tags: "js,node"
    })

    let post = yield client.hgetall.bind(client, "blog::post")
    let tags = post.tags.split(",")
    let taggedPosts = yield parallel(tags.map(function (tag) {
        return client.hgetall.bind(client, "post::tag::" + tag)
    }))

    return { post: post, taggedPosts: taggedPosts }
})(function (err, result) {
    if (err) {
        throw err
    }

    console.log("post", result.post, "taggedPosts", result.taggedPosts)

    client.quit()
})

Installation

npm install gens

Contributors

  • Raynos

MIT Licenced

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free