Skip to content

Commit a766bcf

Browse files
docs: add await operator to ctx.sendEvents() call (#708)
Since `ctx.sendEvents` returns a promise, the `await` operator must be added to the examples.
1 parent 1565a12 commit a766bcf

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

docs/sse.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { Application, Router } from "https://deno.land/x/oak/mod.ts";
2020
const app = new Application();
2121
const 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
3333
on 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
4848
router.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
6767
router.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
124124
router.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

Comments
 (0)