@@ -20,8 +20,8 @@ import { Application, Router } from "https://deno.land/x/oak/mod.ts";
2020const app = new Application ();
2121const router = new Router ();
2222
23- router .get (" /sse" , (ctx ) => {
24- const target = ctx .sendEvents ();
23+ router .get (" /sse" , async (ctx ) => {
24+ const target = await ctx .sendEvents ();
2525 target .dispatchMessage ({ hello: " world" });
2626});
2727
@@ -33,8 +33,8 @@ The far end can close the connection, which can be detected by the `close` event
3333on the target:
3434
3535``` ts
36- router .get (" /sse" , (ctx ) => {
37- const target = ctx .sendEvents ();
36+ router .get (" /sse" , async (ctx ) => {
37+ const target = await ctx .sendEvents ();
3838 target .addEventListener (" close" , (evt ) => {
3939 // perform some cleanup activities
4040 });
@@ -46,7 +46,7 @@ The server side can also close the connection:
4646
4747``` ts
4848router .get (" /sse" , async (ctx ) => {
49- const target = ctx .sendEvents ();
49+ const target = await ctx .sendEvents ();
5050 target .dispatchMessage ({ hello: " world" });
5151 await target .close ();
5252});
@@ -65,7 +65,7 @@ server and dispatched via the `ServerSentEventTarget` will be raised as a
6565
6666``` ts
6767router .get (" /sse" , async (ctx : Context ) => {
68- const target = ctx .sendEvents ();
68+ const target = await ctx .sendEvents ();
6969 const event = new ServerSentEvent (" ping" , { hello: " world" });
7070 target .dispatchEvent (event );
7171});
@@ -123,7 +123,7 @@ when calling `.sendEvents()`:
123123``` ts
124124router .get (" /sse" , async (ctx : Context ) => {
125125 const headers = new Headers ([[" X-Custom-Header" , " custom value" ]]);
126- const target = ctx .sendEvents ({ headers });
126+ const target = await ctx .sendEvents ({ headers });
127127 const event = new ServerSentEvent (" ping" , { hello: " world" });
128128 target .dispatchEvent (event );
129129});
0 commit comments