Skip to content

Commit

Permalink
New: Added support for returning the last state of an observable
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonmoeller authored and phated committed May 17, 2016
1 parent 2b49535 commit 9852b3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ var tick = require('next-tick');
var once = require('once');
var exhaust = require('stream-exhaust');

function noop(){}

var eosConfig = {
error: false
};
Expand Down Expand Up @@ -37,6 +35,14 @@ function asyncDone(fn, cb){
function asyncRunner(){
var result = domainBoundFn(done);

function onNext(state) {
onNext.state = state;
}

function onCompleted() {
return onSuccess(onNext.state);
}

if(result && typeof result.on === 'function'){
// assume node stream
d.add(result);
Expand All @@ -46,7 +52,7 @@ function asyncDone(fn, cb){

if(result && typeof result.subscribe === 'function'){
// assume RxJS observable
result.subscribe(noop, onError, onSuccess);
result.subscribe(onNext, onError, onCompleted);
return;
}

Expand Down
6 changes: 1 addition & 5 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ describe('observables', function(){
});
});

/*
Currently, we don't support values returned from observables.
This keeps the code simpler.
*/
it.skip('should handle a finished observable with value', function(done){
it('should handle a finished observable with value', function(done){
asyncDone(successValue, function(err, result){
expect(result).to.equal(42);
done(err);
Expand Down

0 comments on commit 9852b3d

Please sign in to comment.