Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.41 KB

from_node_callback.md

File metadata and controls

54 lines (37 loc) · 1.41 KB

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.

Arguments

  1. func (Function): Callback function which must be in function (err, ...) format.
  2. [scheduler = Rx.Scheduler.timeout] (Scheduler): Scheduler used to execute the callback.
  3. [context] (Any): The context to execute the callback.

Returns

(Function): An function which when applied, returns an observable sequence with the callback arguments as an array.

Example

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

{% if book.isPdf %}

{% else %}

Location

  • rx.node.js

{% endif %}