Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisaruGuruge committed Apr 16, 2024
1 parent f85f3fe commit 15993b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/graphql-subscriptions/graphql_subscriptions.bal
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ service /graphql on new graphql:Listener(9090) {
// `Subscription` operation. It must always return a stream. Since the stream is of type
// `string`, the resulting field in the generated GraphQL schema will be of type `String!`.
resource function subscribe names() returns stream<string, error?> {
// Create a `NameGenerator` object.
NameGenerator nameGenerator = new (self.names);
// Create a stream using the `NameGenerator` object.
stream<string, error?> names = new (nameGenerator);
return names;
}
}

// Defines a StreamGenerator class that can be used to create a stream of strings. This will pick a random name from
// Defines a stream implementor that can be used to create a stream of strings. This will pick a random name from
// the list of names and return it with a delay to demonstrate a stream of values.
class NameGenerator {
private final string[] names;
Expand All @@ -28,7 +30,7 @@ class NameGenerator {
self.names = names;
}

// Function that picks a random name from the list and returns it.
// The `next` method picks a random name from the list and returns it.
public isolated function next() returns record {|string value;|}|error? {
// Sleep for 1 second to simulate a delay.
runtime:sleep(1);
Expand Down

0 comments on commit 15993b0

Please sign in to comment.