Skip to content
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

sse syntax update concept #311

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pkieltyka
Copy link
Member

  • AbortController will automatically be created if one is not passed in
  • Stream call returns the abort function on the controller, and also a .wait in case someone wants to block until the connection is done..? maybe we think of another name, and perhaps this isn't very useful or we should modify this to a fan out thing, as I imagine if its called multiple times, it won't work very well..
  • the primary reason for this change though is to simplify how developers need to think about the AbortController and instead return it as part of the API as the default option while preserving previous functionality / capability

@pkieltyka pkieltyka marked this pull request as draft September 30, 2024 17:51
Comment on lines 77 to 81
const stream = api.subscribeMessages(
{ username },
{ onMessage, onError, onOpen, onClose }//, signal: controller }
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the returned stream.abort() reads if you don't provide your own 👍

const resp = _fetch();
return {
abort: abortController.abort.bind(abortController),
wait: resp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have onClose(), perhaps we don't need this wait return argument

or is there a use-case for awaiting stream right away and blocking on the operation? is it idiomatic?

await stream.closed

this would have to raise exception, that you can normally get through onError()

@AlexanderKolberg thoughts?

export interface WebrpcOptions {
headers?: HeadersInit;
signal?: AbortSignal;
controller?: AbortController;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed from signal to controller here. Let me know if you guys think this is fine or if it breaks any functionality / uses from before?

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.

3 participants