-
Notifications
You must be signed in to change notification settings - Fork 14
Support context on request methods. #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This would typically be used by clients to implement cancellation.
|
Is there a type that would be better to use than |
ts/src/facilityCore.ts
Outdated
| /** The fetch function. */ | ||
| export interface IFetch { | ||
| (uri: string, request: IFetchRequest): Promise<IFetchResponse>; | ||
| (uri: string, request: IFetchRequest, context?: any): Promise<IFetchResponse>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use unknown instead of any, which would force a type check/cast where it's used.
It's nice that IFetchRequest is compatible with fetch's init. Did you consider adding a signal of type any or unknown to that interface instead of separate parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
unknowninstead ofany, which would force a type check/cast where it's used.
That sounds nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider adding a
signalof typeanyorunknownto that interface instead of separate parameter?
I'm not intuitively excited about the idea, but I'm willing to be convinced. I like the context being ignored unless the caller explicitly does something with it. I wouldn't want people to get the idea that it "should" be an AbortSignal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetch(uri, { ...request, signal: context as AbortSignal? })It seems fine.
node-fetch doesn't have signal in its RequestInit type anyway, at least in the version I happen to have in the project I'm currently working on.
This would typically be used by clients to implement cancellation.
Fixes #17.
My npm/js/ts knowledge is so weak and obsolete that I don't know how to build and publishfacility-core(ints/src).