Replies: 1 comment 3 replies
-
.NET's That said, I could perhaps make it an error to pass a cancellation token for the It would be feasible to indicate this in the type system as well, if a bit awkward, e.g.: export declare function delay<T>(msec: number, value: T): T extends Cancelable ? never : Promise<Awaited<T>>; |
Beta Was this translation helpful? Give feedback.
-
Hi Ron, first of all, many thanks for this library! Obviously, an enormous amount of time and efforts has gone into maintaining it. And for some of us who's switching back and forth between TypeScript and C#, the functionality it provides is simply indispensable.
I've just bumped into an error where I was using
await delay(ms, cancelToken)
instead ofawait delay(cancelToken, ms)
, and it took me a good hour to figure out why the delay wasn't getting cancelled. Of course it was because this override was happily acceptingcancelToken
as the 2nd argument:export declare function delay<T>(msec: number, value: T | PromiseLike<T>): Promise<T>;
I wonder if could do something about it, like maybe give it a runtime check inside
delay
?In .NET, the cancellation token is always passed as a last argument by convention (and
Task.Delay(ms, token)
follows that). That's how I got there in the first place :) Is that's OK by you, I could submit a PR.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions