continuable-generators

Experimental usage of generators for continuables

Usage no npm install needed!

<script type="module">
  import continuableGenerators from 'https://cdn.skypack.dev/continuable-generators';
</script>

README

continuable-generators

NPM version

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.

Example

// 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 (err, result) {
    if (err) {
        throw err
    }

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

    client.quit()
})

Installation

npm install continuable-generators

Contributors

  • Raynos

MIT Licenced