We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d8fa7fc commit 3aa07e4Copy full SHA for 3aa07e4
1 file changed
src/hx/concurrent/event/EventDispatcherWithHistory.hx
@@ -37,12 +37,20 @@ class EventDispatcherWithHistory<EVENT> implements EventDispatcher<EVENT> {
37
if (listener == null)
38
throw "[listener] must not be null";
39
40
- if (_wrapped.subscribe(listener)) {
41
- for (event in _eventHistory)
+ // Take a snapshot and subscribe while holding the history lock to avoid
+ // losing events that might be fired between snapshot and subscription.
42
+ var history:Array<EVENT>;
43
+ var added = false;
44
+ _eventHistoryLock.execute(() -> {
45
+ history = _eventHistory.copy();
46
+ added = _wrapped.subscribe(listener);
47
+ });
48
+
49
+ if (added) {
50
+ for (event in history)
51
listener(event);
52
return true;
53
}
-
54
return false;
55
56
0 commit comments