Created
May 17, 2016 21:53
-
-
Save jadbox/8fed38ae730e8fb6a909edb9f6deae0c to your computer and use it in GitHub Desktop.
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
import most, { | |
create, of, from | |
} | |
from 'most'; | |
function fromNodeCallback(fun) { | |
return (...x) => create((add, end, error) => { | |
x.push(handleNodeCB); | |
fun.apply(null, x); | |
}); | |
} | |
function flatMapNode(fun) { | |
return this.flatMap(x => | |
create((add, end, error) => { | |
fun(x, handleNodeCB); | |
}) | |
); | |
} | |
function handleNodeCB(add, end, error) { | |
return (err, res) => { | |
if (err) error(err); | |
else { | |
add(res); | |
end(); | |
} | |
}; | |
} | |
module.exports = { | |
node: fromNodeCallback, | |
fromNodeCallback, // alias | |
bindNodeCallback: fromNodeCallback, // alias | |
flatMapNode, | |
chainNode: flatMapNode, | |
create, | |
of, | |
most, | |
from | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment