Rx.Observable.fromNodeCallback(func, [context], [selector])
Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
Arguments
func
(Function
): Function with a callback as the last parameter to convert to an Observable sequence.[context]
(Any
): The context for the func parameter to be executed. If not specified, defaults to undefined.[selector]
(Function
): A selector which takes the arguments from callback sans the error to produce a single item to yield on next.
Returns
(Function
): A function which when applied, returns an observable sequence with the callback arguments as an array if no selector given, else the object created by the selector function on success, or an error if the first parameter is not falsy.
Example
var fs = require('fs'),
Rx = require('rx');
// Wrap fs.rename
var rename = Rx.Observable.fromNodeCallback(fs.rename);
// Rename file which returns no parameters except an error
var source = rename('file1.txt', 'file2.txt');
var subscription = source.subscribe(
function () {
console.log('Next: success!');
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: success!
// => Completed
Location
File:
Dist:
Prerequisites:
- If using
rx.async.js
|rx.async.compat.js
rx
.lite.js | rx.lite.compat.js
NPM Packages:
NuGet Packages:
Unit Tests: