-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed todo related to properly halting the stream (#98)
- Loading branch information
1 parent
3b62272
commit 8675c99
Showing
1 changed file
with
4 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,10 @@ | ||
import highland from 'highland'; | ||
import _ from 'lodash'; | ||
|
||
function defaultExecuteHandler(messageStream, callback) { | ||
let errored = false; | ||
let objectMode = false; | ||
|
||
const defaultExecuteHandler = (messageStream, callback) => | ||
highland(messageStream) | ||
.stopOnError(err => { | ||
// TODO: this does not seem to halt the stream properly, and make | ||
// the callback being fired twice. We need to get rid of the ugly | ||
// errored variable check. | ||
errored = true; | ||
callback(err); | ||
}) | ||
.map(({ result: { data } }) => { | ||
objectMode = !_.isArray(data); | ||
|
||
return data; | ||
}) | ||
.map(({ result: { data } }) => data) | ||
.sequence() | ||
.toArray(results => { | ||
if (!errored) { | ||
callback(null, objectMode ? results[0] : results); | ||
} | ||
}); | ||
} | ||
.collect() | ||
.toCallback(callback); | ||
|
||
export default defaultExecuteHandler; |