javascript - How can I redirect a stream based in an "internal state" -
I am writing a plugin for blog which uses a web service and one or the other thing Uses. The algorithm is something like:
stream1 = through.obj (function (src, enc, cb) {if src.is_a_buffer () http_request (options) http_request.on ('response', function ( ) {If (statusCode = 200) • General course, everything works fine * / do_something () Return cb ()} and {/ * exception courses, though Section 2 has been created, 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 ()});
When I run the code stream 2. never gets. Since I'm new to the node stream, I think I have misunderstood something. Do any of you help me understand that what is wrong with me?
When you call stream1.pipe (stream 2 ())
, stream 1 The data already emitted (possibly all this); that execution of that call will not be passed on
stream2
Note: I am just modifying the original pseudocode I
V Article 1:
Do not bother with a stream2
and call directly do_other_stuff ()
directly:
stream1 = through.obj (function (src, enc, cb) {if src.is_a_buffer () http_request (options) http_request.on ('response', function () {if (statusCode = 200) {/ * Normally, everything works well * / do_something () cb ()} and {do_other_stuff () cb ()}}, function (cb) {cb ()});
Option 2:
If you need stream2
for other purposes, then Callback out to.obj ()
Callable function and call it directly from your second section.
I hope that Helps :)
Comments
Post a Comment