Skip to content

Commit 9852b3d

Browse files
shannonmoellerphated
authored andcommitted
New: Added support for returning the last state of an observable
1 parent 2b49535 commit 9852b3d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ var tick = require('next-tick');
77
var once = require('once');
88
var exhaust = require('stream-exhaust');
99

10-
function noop(){}
11-
1210
var eosConfig = {
1311
error: false
1412
};
@@ -37,6 +35,14 @@ function asyncDone(fn, cb){
3735
function asyncRunner(){
3836
var result = domainBoundFn(done);
3937

38+
function onNext(state) {
39+
onNext.state = state;
40+
}
41+
42+
function onCompleted() {
43+
return onSuccess(onNext.state);
44+
}
45+
4046
if(result && typeof result.on === 'function'){
4147
// assume node stream
4248
d.add(result);
@@ -46,7 +52,7 @@ function asyncDone(fn, cb){
4652

4753
if(result && typeof result.subscribe === 'function'){
4854
// assume RxJS observable
49-
result.subscribe(noop, onError, onSuccess);
55+
result.subscribe(onNext, onError, onCompleted);
5056
return;
5157
}
5258

test/observables.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ describe('observables', function(){
3030
});
3131
});
3232

33-
/*
34-
Currently, we don't support values returned from observables.
35-
This keeps the code simpler.
36-
*/
37-
it.skip('should handle a finished observable with value', function(done){
33+
it('should handle a finished observable with value', function(done){
3834
asyncDone(successValue, function(err, result){
3935
expect(result).to.equal(42);
4036
done(err);

0 commit comments

Comments
 (0)