【发布时间】:2014-09-19 02:02:00
【问题描述】:
我正在为 gulp 编写一个使用 Web 服务的插件,并根据响应做一件事或另一件事。算法是这样的:
stream1 = through.obj(function(src, enc, cb) {
if src.is_a_buffer()
http_request(options)
http_request.on('response', function () {
if (statusCode = 200) {
/* Normal course, everything works fine here */
do_something()
return cb()
} else {
/* Exception course, although the stream2 is created, is never executed */
stream1.pipe(stream2())
}
}, function (cb) {
cb()
});
stream2 = through.obj(function(src,enc,cb) {
do_other_stuff()
stream2.push(src)
return cb()
}, function (cb) {
cb()
});
当我运行代码 stream2 时,它永远不会执行。 由于我是节点流的新手,我想我误解了一些东西。你们中的任何人都可以帮助我理解我在这里做错了什么吗?
【问题讨论】:
-
这应该是纯 javascript 还是转换为 javascript 的语言?如果是前者,那么右侧值为
return <value>的赋值是无效的 javascript ... -
@mscdex 我的错。已编辑
标签: javascript node.js stream gulp