Skip to content

Commit

Permalink
fix: Fixes and simplifies the Countdown subscription example for Real…
Browse files Browse the repository at this point in the history
…time (#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
  • Loading branch information
dthyresson authored Jul 6, 2023
1 parent 42f5c04 commit 1368550
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
},
Expand Down

0 comments on commit 1368550

Please sign in to comment.