fromNodeCallback
Rx.Node.fromNodeCallback(func, [scheduler], [context])
Deprecated in favor of Rx.Observable.fromNodeCallback
in rx.async.js.
Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
参数
func
(Function): Callback function which must be in function (err, ...) format.[scheduler = Rx.Scheduler.timeout]
(Scheduler): Scheduler used to execute the callback.[context]
(Any): The context to execute the callback.
返回值
(Function): An function which when applied, returns an observable sequence with the callback arguments as an array.
例
var fs = require('fs');
var Rx = require('Rx');
var source = Rx.Node.fromNodeCallback(fs.stat)('file.txt');
var observer = Rx.Observer.create(
function (x) {
var stat = x[0];
console.log('Next: ' + stat.isFile());
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
}
);
var subscription = source.subscribe(observer);
// => Next: true
// => Completed