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.
- Reword some comments.

Closes #41
  • Loading branch information
demurgos committed May 8, 2018
1 parent 78ea929 commit 592b94e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
11 changes: 7 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,10 @@ 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
[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
12 changes: 6 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@
*/
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import { Readable as ReadableStream } from "stream";
import { Stream } from "stream";

declare namespace asyncDone {

/**
* Represents a callback function used to signal the completion of a
* task that does not return any completion value.
* task without any result value.
*/
type VoidCallback = (err: Error | null) => void;

/**
* Represents a callback function used to signal the completion of a
* task that does return a single completion value.
* task with a single result value.
*/
interface Callback<T> {
(err: null, result: T): void;

// Set the type of `result` to `T` if you want to enforce stricter callback functions.
// (See comment above about risks of unsound type checking)
// Use `result?: T` or `result: undefined` to require the consumer to assert the existence of the result
// (even in case of success). See comment at the top of the file.
(err: Error, result?: any): void;
}

Expand All @@ -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 592b94e

Please sign in to comment.