From e67fe591c5881c0b38089daf9432d7275b70bb77 Mon Sep 17 00:00:00 2001 From: Muzzammil Shahid Date: Sat, 11 May 2024 16:59:21 +0500 Subject: [PATCH] Fix ClientSideLocalBaseSession to wait only when incoming messages are empty --- lib/src/types.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/types.dart b/lib/src/types.dart index be30ff9..4eaf043 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -229,7 +229,7 @@ class ClientSideLocalBaseSession implements IBaseSession { String authrole() => _authrole; @override - serializer() => _serializer; + Serializer serializer() => _serializer; @override Future send(Object data) async { @@ -238,8 +238,11 @@ class ClientSideLocalBaseSession implements IBaseSession { @override Future receive() async { - await _completer.future; - _completer = Completer(); + if (_incomingMessages.isEmpty) { + await _completer.future; + _completer = Completer(); + } + return _incomingMessages.removeFirst(); } @@ -258,7 +261,9 @@ class ClientSideLocalBaseSession implements IBaseSession { Future feed(Object data) async { _incomingMessages.add(data); - _completer.complete(); + if (!_completer.isCompleted) { + _completer.complete(); + } } }