javascript - how to destroy a highland stream -
i have following example
const input = _(); const output = _() .each(x => console.log('out', x)); input .pipe(output); input.write(1) output.destroy(); input.write(2); as far can read in documentation (http://highlandjs.org/#destroy) destroying stream should clean broken pipe. in stead following error:
out 1 out 2 node_modules/highland/lib/index.js:1114 throw new error('can not call next after nil'); ^ error: can not call next after nil does have insight why happends, , correct way destroy stream is?
from reading documentation, looks this answer error. way in stream lets rest of program know has ended passing "nil" next piece of data on stream. looking @ sample code @ link, it's determine stream has ended , act accordingly.
that's why you're getting error - pipe trying continue on next data, throwing error there no such thing next after "nil".
as correct way destroy stream, think way using correct way (i'm not familiar highland.js, that's based on reading documentation , familiarity javascript in general), it's effects aren't you're expecting. not expect destroying output destroy pipe, because pipe "belongs" input, called against. if want destroy pipe, imagine way go call
input.destroy() instead (or indeed, output.destroy(), don't want leave loose ends!). documentation states should call destroy() or .end() on manually constructed stream (like have above).
think way. if have source piping destination, , remove destination, of course i'm going error, because input has go, , output stream going telling else has ended. if want destroy pipe, makes more sense destroy source, , if stop output/destination, need find somewhere else input go!
Comments
Post a Comment