Created
November 14, 2017 16:25
-
-
Save AdamSaleh/4de5b8cc1e4ce8a0ae4c67d26904b8e7 to your computer and use it in GitHub Desktop.
purescriptStreamToAff
This file contains hidden or 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
'use strict'; | |
exports._collapseStream = function (stream) { // accepts a request | |
return function (onError, onSuccess) { // and callbacks | |
var buffer = ''; | |
stream.on('data', (d) => { buffer = buffer + d; }); | |
stream.on('err', (err) => onError(err)); | |
stream.on('end', () => onSuccess(buffer)); | |
// Return a canceler, which is just another Aff effect. | |
return function (cancelError, cancelerError, cancelerSuccess) { | |
stream.pause(); // cancel the request | |
cancelerSuccess(); // invoke the success callback for the canceler | |
}; | |
}; | |
}; |
This file contains hidden or 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
foreign import _collapseStream :: forall w e. Stream.Readable w e -> EffFnAff e String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment