From 1368550bcfe74e1466b52218cdbb6cb8d11bb911 Mon Sep 17 00:00:00 2001 From: David Thyresson Date: Thu, 6 Jul 2023 11:22:30 -0400 Subject: [PATCH] fix: Fixes and simplifies the Countdown subscription example for Realtime (#8838) This PR fixes the issue where: * the countdown example actually uses the interval to count down by ... and * also has a reasonable count pause --- .../subscriptions/countdown/countdown.ts.template | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/experimental/templates/subscriptions/countdown/countdown.ts.template b/packages/cli/src/commands/experimental/templates/subscriptions/countdown/countdown.ts.template index ff46abf1fdd0..bf42145b1025 100644 --- a/packages/cli/src/commands/experimental/templates/subscriptions/countdown/countdown.ts.template +++ b/packages/cli/src/commands/experimental/templates/subscriptions/countdown/countdown.ts.template @@ -10,15 +10,17 @@ export const schema = gql` * To test this Countdown subscription, run the following in the GraphQL Playground: * * subscription CountdownFromInterval { - * countdown(from: 10, interval: 100) + * countdown(from: 100, interval: 10) * } */ const countdown = { countdown: { - async *subscribe(_, { from, interval }) { - for (let i = from; i >= 0; i--) { - await new Promise((resolve) => setTimeout(resolve, interval ?? 1000)) - yield { countdown: i } + async *subscribe(_, { from = 100, interval = 10 }) { + while (from >= 0) { + yield { countdown: from } + // pause for 1/4 second + await new Promise((resolve) => setTimeout(resolve, 250)) + from -= interval } }, },