Skip to content

Commit

Permalink
Minor fixes to type definitions
Browse files Browse the repository at this point in the history
- Document support for RxJS 4 and 5
- Accept `Stream` as a return value instead of `Readable`
- Remove dummy body in stream tests.

Closes #41
  • Loading branch information
demurgos committed Jan 24, 2018
1 parent 78ea929 commit 0aec7a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Optionally takes a callback to call when async tasks are complete.
* `Promise` returned
- Completion: [onFulfilled][promise-onfulfilled] method called
- Error: [onRejected][promise-onrejected] method called
* `Observable` returned
- Completion: [onCompleted][observable-subscribe] method called
- Error: [onError][observable-subscribe] method called
* `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs5-observable]) returned
- Completion: [complete][rxjs5-subscriber-complete] method called
- Error: [error][rxjs5-subscriber-error] method called

__Warning:__ Sync tasks are __not supported__ and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain.

Expand All @@ -96,7 +96,11 @@ MIT
[event-stream]: https://github.com/dominictarr/event-stream
[promise-onfulfilled]: http://promisesaplus.com/#point-26
[promise-onrejected]: http://promisesaplus.com/#point-30
[observable-subscribe]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/subscribe.md
[rx4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md
[rx4-observable-subscribe]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/subscribe.md
[rxjs5-observable]: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html
[rxjs5-observer-complete]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-complete
[rxjs5-observer-error]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-error

[downloads-image]: http://img.shields.io/npm/dm/async-done.svg
[npm-url]: https://www.npmjs.com/package/async-done
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import { Readable as ReadableStream } from "stream";
import { Stream } from "stream";

declare namespace asyncDone {

Expand Down Expand Up @@ -87,7 +87,7 @@ declare namespace asyncDone {
export type AsyncTask<R = any> =
((done: VoidCallback) => void)
| ((done: Callback<R>) => void)
| (() => ChildProcess | EventEmitter | Observable<R> | PromiseLike<R> | ReadableStream );
| (() => ChildProcess | EventEmitter | Observable<R> | PromiseLike<R> | Stream);
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function success() {
}

function successValue() {
// This corresponds to `Observable.return(42);` in RxJS 4
return Observable.of(42);
}

Expand Down
20 changes: 2 additions & 18 deletions test/types/streams.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
import asyncDone from "async-done";
import { Readable, Stream } from "stream";

function readableSuccess(): Readable {
return undefined as any;
}

function readableFail(): Readable {
return undefined as any;
}

function streamSuccess(): Stream {
return undefined as any;
return new Stream();
}

function streamFail(): Stream {
return undefined as any;
return new Stream();
}

asyncDone(readableSuccess, function (err: Error | null): void {
console.log("Done");
});

asyncDone(readableFail, function (err: Error | null): void {
console.log("Done");
});

asyncDone(streamSuccess, function (err: Error | null): void {
console.log("Done");
});
Expand Down

0 comments on commit 0aec7a4

Please sign in to comment.