Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Rx.spawn doesn't work #700

Closed
xgrommx opened this issue May 10, 2015 · 4 comments
Closed

Rx.spawn doesn't work #700

xgrommx opened this issue May 10, 2015 · 4 comments

Comments

@xgrommx
Copy link
Contributor

xgrommx commented May 10, 2015

Hello @mattpodwysocki. I tried use this example, but this example doesn't work:

var source = Rx.spawn(function* () {
    yield Observable.just(1);
    yield Promise.resolve(2);
    yield 3;
})();

var subscription = source.subscribe(
    function (x) {
        console.log('Next: %s', x);
    },
    function (err) {
        console.log('Error: %s', err);
    },
    function () {
        console.log('Completed');
    });
@xgrommx
Copy link
Contributor Author

xgrommx commented May 13, 2015

This isn't actually. I got it. Will be better if Rx.spawn return an observable.

@xgrommx xgrommx closed this as completed May 13, 2015
@xgrommx xgrommx reopened this May 13, 2015
@mattpodwysocki
Copy link
Member

@xgrommx I see your point as libraries such as co return promises. I'll work on getting that in there for the next release.

@xgrommx
Copy link
Contributor Author

xgrommx commented May 13, 2015

@mattpodwysocki I proposed pull request to co but it was rejected https://github.com/xgrommx/co/blob/master/index.js#L121. Reason - an observable isn't standard yet.

@jaawerth
Copy link

What is the expected behavior, though? Does Rx work at all? The docs have the example in the OP and suggest rx.spawn returns an observable, but this doesn't seem to be the case - it returns undefined for me and doesn't execute at all if I use Rx.Observable.just in the first yield, and if I remove that and try yielding promises or values I get the following error, regardless of what it tries to return:

  'use strict';
var Rx = require('rx');

var gen = Rx.spawn(function* () { 
  var r1 = yield 1;
  var r2 = yield 2;
  console.log('running');
  console.log(r1, r2);
})();

var source = gen();

Error (running the above in either a node environment with regenerator, or in iojs):

/home/jesse/rxtest/node_modules/rx/dist/rx.async.js:59
    if (isPromise(obj)) { return promiseToThunk(obj); }
        ^
ReferenceError: isPromise is not defined
    at toThunk (/home/jesse/rxtest/node_modules/rx/dist/rx.async.js:59:9)
    at next (/home/jesse/rxtest/node_modules/rx/dist/rx.async.js:205:21)
    at /home/jesse/rxtest/node_modules/rx/dist/rx.async.js:171:7
    at Object.<anonymous> (/home/jesse/rxtest/rxtest.js:11:14)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:428:10)
    at Module.load (module.js:335:32)
    at Function.Module._load (module.js:290:12)
    at Function.Module.runMain (module.js:451:10)
    at startup (node.js:123:18)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants