Last active
October 3, 2018 05:00
-
-
Save ORESoftware/ea5d754d6ca6c92ca7e3bddc7eb318c2 to your computer and use it in GitHub Desktop.
Rx.Observable - bindCallback (as opposed to bindNodeCallback)
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
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