| 451 | write<WireTrails>(`api/trails/${encodeURIComponent(id)}`, 'DELETE', undefined, signal), |
| 452 | |
| 453 | events(handlers) { |
| 454 | if (typeof EventSource === 'undefined') return () => {}; |
| 455 | const stream = new EventSource(`${base}api/events`); |
| 456 | stream.addEventListener('hello', (event) => handlers.hello(parse(event))); |
| 457 | stream.addEventListener('changed', (event) => handlers.changed(parse(event))); |
| 458 | stream.addEventListener('index', (event) => handlers.index(parse(event))); |
| 459 | stream.addEventListener('degraded', (event) => handlers.degraded(parse(event))); |
| 460 | // The backoff belongs to the caller, not here: an adapter that retried on |
| 461 | // its own would race the one that already does and double the requests. |
| 462 | stream.addEventListener('error', () => handlers.error()); |
| 463 | return () => stream.close(); |
| 464 | }, |
| 465 | }; |
| 466 | } |
| 467 | |