You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Visit our [Web Site](https://docs.amplify.aws/) to learn more about AWS Amplify.
25
-
26
-
## Changes for version 0.3.0 and above
27
-
28
-
When creating subscriptions, now, a [`Stream`](https://api.dart.dev/stable/dart-async/Stream-class.html) object will be returned to you. This `Stream` will continue producing events until either the subscription encounters an error, or you cancel the subscription. In the case of [`await for`](https://dart.dev/tutorials/language/streams), this cancellation occurs when breaking out of the loop.
29
-
30
-
```dart
31
-
Future<void> subscribe() async {
32
-
final graphQLDocument = '''subscription MySubscription {
33
-
onCreateBlog {
34
-
id
35
-
name
36
-
createdAt
37
-
}
38
-
}''';
39
-
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
print('Subscription event data received: ${event.data}');
50
-
if (i == 5) {
51
-
break;
52
-
}
53
-
}
54
-
} on Exception catch (e) {
55
-
print('Error in subscription stream: $e');
56
-
}
57
-
}
58
-
```
59
-
60
-
Alternatively, you can call [`Stream.listen`](https://api.dart.dev/stable/dart-async/Stream/listen.html) to create a [`StreamSubscription`](https://api.dart.dev/stable/dart-async/StreamSubscription-class.html) object which can be programmatically canceled.
61
-
62
-
```dart
63
-
Future<void> subscribe() async {
64
-
final graphQLDocument = '''subscription MySubscription {
65
-
onCreateBlog {
66
-
id
67
-
name
68
-
createdAt
69
-
}
70
-
}''';
71
-
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
0 commit comments