|
1 | 1 | import type { Promisable, Value } from '@orpc/shared' |
2 | | -import { |
3 | | - AsyncIteratorClass, |
4 | | - isAsyncIteratorObject, |
5 | | - override, |
6 | | - sleep, |
7 | | - toArray, |
8 | | - value, |
9 | | -} from '@orpc/shared' |
| 2 | +import { AsyncIteratorClass, isAsyncIteratorObject, sleep, toArray, value } from '@orpc/shared' |
10 | 3 | import { getEventMeta } from '@standard-server/core' |
11 | 4 |
|
12 | 5 | import type { |
@@ -226,50 +219,47 @@ export class RetryLinkPlugin< |
226 | 219 |
|
227 | 220 | let current = output |
228 | 221 |
|
229 | | - return override( |
230 | | - () => current, |
231 | | - new AsyncIteratorClass( |
232 | | - async () => { |
233 | | - while (true) { |
234 | | - try { |
235 | | - const item = await current.next() |
236 | | - const meta = getEventMeta(item.value) |
237 | | - |
238 | | - lastEventId = meta?.id ?? lastEventId |
239 | | - lastEventRetry = meta?.retry ?? lastEventRetry |
240 | | - |
241 | | - return item |
242 | | - } catch (error) { |
243 | | - const meta = getEventMeta(error) |
244 | | - |
245 | | - lastEventId = meta?.id ?? lastEventId |
246 | | - lastEventRetry = meta?.retry ?? lastEventRetry |
247 | | - |
248 | | - const asyncIteratorObject = await callNext({ error }) |
249 | | - if (!isAsyncIteratorObject(asyncIteratorObject)) { |
250 | | - throw new TypeError( |
251 | | - 'RetryLinkPlugin: Expected an AsyncIteratorObject, got a different type.', |
252 | | - { cause: error }, |
253 | | - ) |
254 | | - } |
255 | | - |
256 | | - current = asyncIteratorObject |
257 | | - |
258 | | - if (isIteratorAborted) { |
259 | | - await current.return?.() |
260 | | - throw error |
261 | | - } |
| 222 | + return new AsyncIteratorClass( |
| 223 | + async () => { |
| 224 | + while (true) { |
| 225 | + try { |
| 226 | + const item = await current.next() |
| 227 | + const meta = getEventMeta(item.value) |
| 228 | + |
| 229 | + lastEventId = meta?.id ?? lastEventId |
| 230 | + lastEventRetry = meta?.retry ?? lastEventRetry |
| 231 | + |
| 232 | + return item |
| 233 | + } catch (error) { |
| 234 | + const meta = getEventMeta(error) |
| 235 | + |
| 236 | + lastEventId = meta?.id ?? lastEventId |
| 237 | + lastEventRetry = meta?.retry ?? lastEventRetry |
| 238 | + |
| 239 | + const asyncIteratorObject = await callNext({ error }) |
| 240 | + if (!isAsyncIteratorObject(asyncIteratorObject)) { |
| 241 | + throw new TypeError( |
| 242 | + 'RetryLinkPlugin: Expected an AsyncIteratorObject, got a different type.', |
| 243 | + { cause: error }, |
| 244 | + ) |
262 | 245 | } |
263 | | - } |
264 | | - }, |
265 | | - async ({ kind }) => { |
266 | | - isIteratorAborted = true |
267 | 246 |
|
268 | | - if (kind === 'cancelled') { |
269 | | - await current.return?.() |
| 247 | + current = asyncIteratorObject |
| 248 | + |
| 249 | + if (isIteratorAborted) { |
| 250 | + await current.return?.() |
| 251 | + throw error |
| 252 | + } |
270 | 253 | } |
271 | | - }, |
272 | | - ), |
| 254 | + } |
| 255 | + }, |
| 256 | + async ({ kind }) => { |
| 257 | + isIteratorAborted = true |
| 258 | + |
| 259 | + if (kind === 'cancelled') { |
| 260 | + await current.return?.() |
| 261 | + } |
| 262 | + }, |
273 | 263 | ) |
274 | 264 | } |
275 | 265 |
|
|
0 commit comments