-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR #45014 [callback-to-async-iterator] Fixes + allow usage of…
… listener return value in onClose by @affanshahid allow usage of return val from listener in onClose
- Loading branch information
1 parent
922f906
commit e4d3b1b
Showing
2 changed files
with
15 additions
and
10 deletions.
There are no files selected for viewing
10 changes: 7 additions & 3 deletions
10
types/callback-to-async-iterator/callback-to-async-iterator-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { callbackToAsyncIterator } from "callback-to-async-iterator"; | ||
import callbackToAsyncIterator from "callback-to-async-iterator"; | ||
|
||
callbackToAsyncIterator(() => {}); // $ExpectType AsyncIterator<unknown, any, undefined> | ||
callbackToAsyncIterator(async () => {}); // $ExpectType AsyncIterator<unknown, any, undefined> | ||
|
||
callbackToAsyncIterator<string>(() => {}); // $ExpectType AsyncIterator<string, any, undefined> | ||
callbackToAsyncIterator<string>(async () => {}); // $ExpectType AsyncIterator<string, any, undefined> | ||
|
||
callbackToAsyncIterator<string>(async () => {}, { onClose() {} }); // $ExpectType AsyncIterator<string, any, undefined> | ||
|
||
callbackToAsyncIterator<string, number>(async () => 1, { onClose(arg: number) {} }); // $ExpectType AsyncIterator<string, any, undefined> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
// Type definitions for callback-to-async-iterator 1.1 | ||
// Project: https://github.com/withspectrum/callback-to-async-iterator#readme | ||
// Definitions by: Zachary Svoboda <https://github.com/zacnomore> | ||
// Affan Shahid <https://github.com/affanshahid> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// Minimum TypeScript Version: 3.6 | ||
|
||
export interface AsyncifyOptions<T> { | ||
onClose: () => void | T; | ||
onError: () => Error; | ||
buffering: boolean; | ||
export interface AsyncifyOptions<T, R> { | ||
onClose?: (arg: R) => void | T; | ||
onError?: () => Error; | ||
buffering?: boolean; | ||
} | ||
|
||
export function callbackToAsyncIterator<T>( | ||
listener: (callback: (message: T) => void) => void, | ||
options?: AsyncifyOptions<T>, | ||
export default function callbackToAsyncIterator<T, R = void>( | ||
listener: (callback: (message: T) => void) => Promise<R>, | ||
options?: AsyncifyOptions<T, R>, | ||
): AsyncIterator<T>; |