Replies: 1 comment
-
What I would do here is to convert into async for loop as https://dart.dev/tutorials/language/streams#receiving-stream-events Here is code, that is probably wrong, as I did not run trough compiler. Future<void> initRedisSubscribe() async {
while(true){
var redisCommand = await getCurrentRedisConnection();
redisPubSub = PubSub(redisCommand);
redisPubSub.subscribe(['notification']);
final stream = redisPubSub.getStream();
var streamWithoutErrors = stream
.handleError((e) => print('NotificationService redisPubSub error $e'));
await for (final msg in streamWithoutErrors) {
var kind = msg[0];
var data = msg[2];
if (kind == 'message') {
var map = jsonDecode(data);
var notification = Notification.fromMap(map);
sendNotifications(notification);
}
// else {
// print('received non-message ${msg}');
//}
}
// stream is done, back to while
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
implement a way to automatically reconnect or resubscribe if the Redis server is restarted
Beta Was this translation helpful? Give feedback.
All reactions