Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active October 3, 2018 05:00
Show Gist options
  • Save ORESoftware/ea5d754d6ca6c92ca7e3bddc7eb318c2 to your computer and use it in GitHub Desktop.
Save ORESoftware/ea5d754d6ca6c92ca7e3bddc7eb318c2 to your computer and use it in GitHub Desktop.
Rx.Observable - bindCallback (as opposed to bindNodeCallback)
const register = function (cb) {
let m = 0;
setInterval(() => {
m++;
cb(m, (err, v) => {
console.log('we got:', err, v);
});
}, 500);
return cb; // return the anonymous function so it can be referenced by rxjs
};
const {bindCallback} = require('rxjs');
const obs = bindCallback(register((v, cb) => {
setTimeout(() => {
cb(null, v + 'sooo'); // cb is not a function .... wutttt :(
}, 200);
}));
const subscription = obs().subscribe(v => {
console.log('on next:', v);
}, e => {
console.log('on error:', e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment