Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matehat committed May 5, 2024
1 parent 7d20963 commit ce9a9e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/src/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,16 @@ class PhoenixChannel {
);

if (canPush) {
_logger.finest(() => 'Sending out push ${pushEvent.ref}');
pushEvent.send();
} else {
if (_state == PhoenixChannelState.closed) {
throw ChannelClosedError('Can\'t push event on a closed channel');
if (_state == PhoenixChannelState.closed ||
_state == PhoenixChannelState.errored) {
throw ChannelClosedError('Can\'t push event on a $_state channel');
}

_logger.finest(
() => 'Buffering push ${pushEvent.ref} for later send ($_state)');
pushBuffer.add(pushEvent);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ class PhoenixChannelEvent {
value.startsWith(__replyEventName);

/// Whether the event name is a 'channel reply' event
bool get isChannelReply =>
value.startsWith(__chanReplyEventName);
bool get isChannelReply => value.startsWith(__chanReplyEventName);

@override
bool operator ==(Object other) =>
other is PhoenixChannelEvent && other.value == value;

@override
int get hashCode => Object.hash(runtimeType, value);

@override
String toString() => 'PhoenixChannelEvent($value)';
}
7 changes: 5 additions & 2 deletions lib/src/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Push {

_timeoutTimer ??= Timer(timeout!, () {
_timeoutTimer = null;
_logger.warning('Push $ref timed out');
_logger.warning(() => 'Push $ref timed out');
_channel.trigger(Message.timeoutFor(ref));
});
}
Expand Down Expand Up @@ -268,6 +268,7 @@ class Push {
// Remove existing waiters and reset completer
void cleanUp() {
if (_sent) {
_logger.fine('Cleaning up completer');
clearReceivers();
_responseCompleter = Completer();
}
Expand All @@ -279,7 +280,9 @@ class Push {
if (response.event == replyEvent) {
trigger(PushResponse.fromMessage(response));
}
} else {
} else if (event != PhoenixChannelEvent.join) {
_logger.finest(
() => "Completing with error: ${_responseCompleter.hashCode}");
if (!_responseCompleter.isCompleted) {
_responseCompleter.completeError(response);
clearReceivers();
Expand Down

0 comments on commit ce9a9e9

Please sign in to comment.