diff options
author | 2023-06-28 20:22:44 -0400 | |
---|---|---|
committer | 2023-06-29 23:41:11 -0400 | |
commit | 175d327a7c53fb9406caa43ba8b921612476c164 (patch) | |
tree | 0f1e223ba2271d8b38a67fb6fa438cb79cfd8322 /src/js/builtins/EventStream.ts | |
parent | 8a5c78d264fd0d912f3a63cc2a0cdbb234bbd11d (diff) | |
download | bun-175d327a7c53fb9406caa43ba8b921612476c164.tar.gz bun-175d327a7c53fb9406caa43ba8b921612476c164.tar.zst bun-175d327a7c53fb9406caa43ba8b921612476c164.zip |
finish up
Diffstat (limited to 'src/js/builtins/EventStream.ts')
-rw-r--r-- | src/js/builtins/EventStream.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/js/builtins/EventStream.ts b/src/js/builtins/EventStream.ts index f55271228..4dee4faed 100644 --- a/src/js/builtins/EventStream.ts +++ b/src/js/builtins/EventStream.ts @@ -10,9 +10,9 @@ export function getEventStream() { // This field is read by `new Response` $contentType = "text/event-stream"; - constructor(opts: EventStreamOptions) { - if (!opts || !$isCallable(opts.start)) throw new TypeError("EventStream requires an object with `start`"); + constructor(opts?: EventStreamOptions) { var queue: any[] = []; + var started = false; super({ type: "direct", pull: controller => { @@ -28,10 +28,13 @@ export function getEventStream() { } controller.flush(); } - opts.start?.(this); + opts?.start?.(this); + started = true; }, cancel: () => { - opts.cancel?.(this); + if (started) { + opts?.cancel?.(this); + } this.#ctrl = null; }, }); |