Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 2.32 KB

spawn.md

File metadata and controls

66 lines (51 loc) · 2.32 KB

Rx.Observable.spawn(fn)

Spawns a generator function which allows for Promises, Observable sequences, Arrays, Objects, Generators and functions.

Arguments

  1. fn (Function): The spawning function.

Returns

(Observable): An Observable with the final result

Example

var Rx = require('rx');

var thunk = function (val) {
  return function (cb) {
    cb(null, val);
  };
};

var spawned = Rx.Observable.spawn(function* () {
  var v = yield thunk(12);
  var w = yield [24];
  var x = yield Rx.Observable.just(42);
  var y = yield Rx.Observable.just(56);
  var z = yield Promise.resolve(78);
  return v + w[0] + x + y + z;
});

spawned.subscribe(
  function (x) { console.log('next %s', x); },
  function (e) { console.log('error %s', e); },
  function () { console.log('completed'); }
);

// => next 212
// => completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: