Skip to content

Commit 2318012

Browse files
committed
chore: add cleanup function example
1 parent 76ca92a commit 2318012

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/simple/realtime.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ const sink: Sink<ExecutionResult<Price>> = {
2222
},
2323
};
2424

25-
const address = process.argv[2] ?? "0x302cae5dcf8f051d0177043c3438020b89b33218";
26-
const networkId = process.argv[3] ?? "1";
25+
const address =
26+
process.argv[2] ?? "2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv";
27+
const networkId = process.argv[3] ?? "1399811149";
2728

2829
console.log(`subscribing to ${address}:${networkId}`);
2930

3031
// Subscribes to the onPriceUpdated event and just logs out the value to the console
31-
sdk.subscribe<Price, { address: string; networkId: number }>(
32+
const cleanup = sdk.subscribe<Price, { address: string; networkId: number }>(
3233
`
3334
subscription onPriceUpdated($address: String!, $networkId: Int!) {
3435
onPriceUpdated(address: $address, networkId: $networkId) {
@@ -45,3 +46,8 @@ sdk.subscribe<Price, { address: string; networkId: number }>(
4546
},
4647
sink,
4748
);
49+
50+
setTimeout(() => {
51+
console.log("Calling cleanup function to unsubscribe");
52+
cleanup();
53+
}, 5000);

0 commit comments

Comments
 (0)