Skip to content

Commit

Permalink
Support read-only and write-only drivers, closes #24
Browse files Browse the repository at this point in the history
Some drivers don't take in sinks, and some drivers don't return sources.
We definitely shouldn't explode in those cases.
  • Loading branch information
Widdershin committed Jan 19, 2016
1 parent 1728b77 commit d513332
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/restartable.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ export default function restartable (driver, opts = {}) {
function restartableDriver (sink$) {
let filteredSink$ = sink$;

if (pauseSinksWhileReplaying) {
if (sink$ && pauseSinksWhileReplaying) {
filteredSink$ = sink$.filter(_ => !replaying);
}

const source = driver(filteredSink$);

let returnValue;

if (typeof source.subscribe === 'function') {
if (source === undefined || source === null) {
return source;
} else if (typeof source.subscribe === 'function') {
returnValue = recordObservableSource({streams, log}, source);
} else {
returnValue = wrapSource({streams, log}, source);
Expand Down
23 changes: 23 additions & 0 deletions test/node/restartable-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* globals describe, it, before, after */
import assert from 'assert';
import {restartable} from '../../src/restart';
import {Observable} from 'rx';


describe('restartable', () => {
it('handles write only drivers', (done) => {
const testDriver = () => {};

restartable(testDriver)(Observable.empty());

done();
});

it('handles read only drivers', (done) => {
const testDriver = () => Observable.empty();

restartable(testDriver)();

done();
});
});

0 comments on commit d513332

Please sign in to comment.