MCPcopy
hub / github.com/Azure/fetch-event-source / create

Function create

src/fetch.ts:102–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100 const fetch = inputFetch ?? window.fetch;
101 const onopen = inputOnOpen ?? defaultOnOpen;
102 async function create() {
103 curRequestController = new AbortController();
104 try {
105 const response = await fetch(input, {
106 ...rest,
107 headers,
108 signal: curRequestController.signal,
109 });
110
111 await onopen(response);
112
113 await getBytes(response.body, getLines(getMessages(id => {
114 if (id) {
115 // store the id and send it back on the next retry:
116 headers[LastEventId] = id;
117 } else {
118 // don't send the last-event-id header anymore:
119 delete headers[LastEventId];
120 }
121 }, retry => {
122 retryInterval = retry;
123 }, onmessage)));
124
125 onclose?.();
126 dispose();
127 resolve();
128 } catch (err) {
129 if (!curRequestController.signal.aborted) {
130 // if we haven't aborted the request ourselves:
131 try {
132 // check if we need to retry:
133 const interval: any = onerror?.(err) ?? retryInterval;
134 window.clearTimeout(retryTimer);
135 retryTimer = window.setTimeout(create, interval);
136 } catch (innerErr) {
137 // we should not retry anymore:
138 dispose();
139 reject(innerErr);
140 }
141 }
142 }
143 }
144
145 create();
146 });

Callers 2

onVisibilityChangeFunction · 0.85
fetchEventSourceFunction · 0.85

Calls 4

getBytesFunction · 0.90
getLinesFunction · 0.90
getMessagesFunction · 0.90
disposeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…