Skip to content

Commit

Permalink
add Source.fail
Browse files Browse the repository at this point in the history
  • Loading branch information
srijs committed May 22, 2016
1 parent e0984d6 commit d83ee6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/source-spec.ts
Expand Up @@ -45,6 +45,16 @@ describe('Stream', () => {

});

describe('fail', () => {

it('throws an error', () => {
const reason = new Error('some error');
const src = Source.fail(reason);
return chai.expect(src.toArray()).to.eventually.be.rejectedWith(reason);
});

});

describe('concat', () => {

it('concatenates two empty sources', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/source.ts
Expand Up @@ -23,6 +23,12 @@ export class Source<Output> {
});
}

static fail<Output>(reason: Error): Source<Output> {
return new Source(<State, Result>(sink: SinkInterface<Output, State, Result>) => {
return Promise.reject<Result>(reason);
});
}

concat(next: Source<Output>): Source<Output> {
return this.concatAsync(Promise.resolve(next));
}
Expand Down

0 comments on commit d83ee6d

Please sign in to comment.