Skip to content

Instantly share code, notes, and snippets.

@TylorS
Last active October 16, 2016 14:16
Show Gist options
  • Save TylorS/00e37b84498c78f2da3bcd948495f2fd to your computer and use it in GitHub Desktop.
Save TylorS/00e37b84498c78f2da3bcd948495f2fd to your computer and use it in GitHub Desktop.
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