Skip to content

Commit ec3df18

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
refactor: emit status function, to avoid concurrent modifictaion error issue
1 parent ece74f6 commit ec3df18

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,24 @@ private void MessageEmitter<T>(Pubnub pubnubInstance, PNMessageResult<T> message
229229

230230
private void StatusEmitter(Pubnub pubnubInstance, PNStatus status)
231231
{
232-
foreach (var listener in SubscribeListenerList)
232+
try
233233
{
234-
try
235-
{
236-
listener?.Status(pubnubInstance, status);
237-
}
238-
catch (Exception ex)
234+
foreach (var listener in SubscribeListenerList.ToArray())
239235
{
240-
config.Logger?.Error($"error during event handler function, {ex.Message}");
236+
try
237+
{
238+
listener?.Status(pubnubInstance, status);
239+
}
240+
catch (Exception ex)
241+
{
242+
config.Logger?.Warn($"error in status event handler function, {ex.Message}");
243+
}
241244
}
242245
}
246+
catch (Exception ex)
247+
{
248+
config.Logger?.Warn($"Emit Status encounter error: {ex.Message}");
249+
}
243250
}
244-
245251
}
246252
}

0 commit comments

Comments
 (0)