Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@ejball
Copy link
Contributor

@ejball ejball commented Nov 18, 2021

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 publish facility-core (in ts/src).

This would typically be used by clients to implement cancellation.
@ejball
Copy link
Contributor Author

ejball commented Nov 18, 2021

Is there a type that would be better to use than any? Since it is passed along to the client's fetch implementation but is otherwise unused by facility-core, I can't think what would be better. Update: unknown

@ejball ejball requested a review from ddunkin November 18, 2021 22:01
/** The fetch function. */
export interface IFetch {
(uri: string, request: IFetchRequest): Promise<IFetchResponse>;
(uri: string, request: IFetchRequest, context?: any): Promise<IFetchResponse>;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

That sounds nice.

Copy link
Contributor Author

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 signal of type any or unknown to 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.

Copy link
Contributor

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.

@ejball ejball marked this pull request as ready for review November 18, 2021 23:23
@ejball ejball merged commit b1544e8 into FacilityApi:master Nov 19, 2021
@ejball ejball deleted the fetch-context branch November 19, 2021 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support cancellation

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.