Last active
October 16, 2016 14:16
-
-
Save TylorS/00e37b84498c78f2da3bcd948495f2fd 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 {Stream} from 'most' | |
const fromNodeCallBack = fn => (...args) => new Stream(new CallBackSource(fn, args)) | |
class CallBackSource { | |
constructor (fn, args) { | |
this.fn = fn | |
this.args = args | |
} | |
run (sink, scheduler) { | |
const fn = this.fn | |
const args = this.args | |
try { | |
fn(...args, (err, res) => { | |
const t = scheduler.now() | |
if (err) { sink.error(t, err) } | |
sink.event(t, res) | |
sink.end(t, res) | |
}) | |
} catch (e) { | |
sink.error(scheduler.now(), e) | |
} | |
return { dispose: () => {} } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment