Commit e7e0d53aa4421ee02973e1349150612fdd489792
Flatten aborts stream of streams and current nested stream.
Jan Bölsche committed on 9/12/2015, 4:52:57 PMParent: b070cef3deeb553c603e9bae34a2edc14f718595
Files changed
throughs.js | changed |
throughs.js | ||
---|---|---|
@@ -204,16 +204,25 @@ | ||
204 | 204 | |
205 | 205 | var flatten = exports.flatten = function (read) { |
206 | 206 | var _read |
207 | 207 | return function (abort, cb) { |
208 | - if (abort) return read(abort, cb) | |
209 | - if(_read) nextChunk() | |
210 | - else nextStream() | |
208 | + if (abort) { | |
209 | + _read ? _read(abort, function(err) { | |
210 | + read(err || abort, cb) | |
211 | + }) : read(abort, cb) | |
212 | + } | |
213 | + else if(_read) nextChunk() | |
214 | + else nextStream() | |
211 | 215 | |
212 | 216 | function nextChunk () { |
213 | 217 | _read(null, function (err, data) { |
214 | 218 | if (err === true) nextStream() |
215 | - else if (err) cb(err) | |
219 | + else if (err) { | |
220 | + read(true, function(abortErr) { | |
221 | + // TODO: what do we do with the abortErr? | |
222 | + cb(err) | |
223 | + }) | |
224 | + } | |
216 | 225 | else cb(null, data) |
217 | 226 | }) |
218 | 227 | } |
219 | 228 | function nextStream () { |
Built with git-ssb-web