-
-
Save metainfa/9adb0ac4ddaef6bcc598be21893cf352 to your computer and use it in GitHub Desktop.
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
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