staccato

2018-09-14 admin

staccato是什么

什么是staccato,Write to a Node.js stream using the error-first callback style.

staccato使用教程帮助文档

Build Status Coverage Status

Write to a Node.js stream using the error-first callback style. Staccato is part of the Cadence Universe. With it you can feed a stream using error-first callbacks, a write to the stream will block if the stream is paused or if there is too much back-pressure, so you can generate a stream from a Cadence loop and the loop will pause when the stream is full.

var Staccato = require('staccato')
var out = new Staccato(fs.createWriteStream('./out.txt'))

var writer = cadence(function (async, bytes) {
    var written = 0
    var loop = async(function () {
        crypto.randomBytes(1024, async())
    }, function (bytes) {
        written += bytes.length
        out.write(bytes, async())
    }, function () {
        if (written >= bytes) {
            return [ loop.break ]
        }
    })()
})

writer(function (error) { if (error) throw error })

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-40267.html

文章标题:staccato

回到顶部