Skip to content

Commit b12a469

Browse files
docs(client): move ReconnectionScheduler example to companion .examples.ts file
1 parent d18c9b3 commit b12a469

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Type-checked examples for `streamableHttp.ts`.
3+
*
4+
* These examples are synced into JSDoc comments via the sync-snippets script.
5+
* Each function's region markers define the code snippet that appears in the docs.
6+
*
7+
* @module
8+
*/
9+
10+
/* eslint-disable unicorn/consistent-function-scoping -- examples must live inside region blocks */
11+
12+
import type { ReconnectionScheduler } from './streamableHttp.js';
13+
14+
// Stub for a hypothetical platform-specific background scheduling API
15+
declare const platformBackgroundTask: {
16+
schedule(callback: () => void, delay: number): number;
17+
cancel(id: number): void;
18+
};
19+
20+
/**
21+
* Example: Using a platform background-task API to schedule reconnections.
22+
*/
23+
function ReconnectionScheduler_basicUsage() {
24+
//#region ReconnectionScheduler_basicUsage
25+
const scheduler: ReconnectionScheduler = (reconnect, delay) => {
26+
const id = platformBackgroundTask.schedule(reconnect, delay);
27+
return () => platformBackgroundTask.cancel(id);
28+
};
29+
//#endregion ReconnectionScheduler_basicUsage
30+
return scheduler;
31+
}

packages/client/src/client/streamableHttp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface StreamableHTTPReconnectionOptions {
9494
* pending reconnection.
9595
*
9696
* @example
97-
* ```ts
97+
* ```ts source="./streamableHttp.examples.ts#ReconnectionScheduler_basicUsage"
9898
* const scheduler: ReconnectionScheduler = (reconnect, delay) => {
9999
* const id = platformBackgroundTask.schedule(reconnect, delay);
100100
* return () => platformBackgroundTask.cancel(id);

0 commit comments

Comments
 (0)