You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-15Lines changed: 24 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@
86
86
import"atomicgo.dev/event"
87
87
```
88
88
89
-
Package event provides a generic event system for Go.
89
+
Package event provides a generic and thread\-safe event system for Go. It allows multiple listeners to subscribe to events carrying data of any type. Listeners can be added and notified when events are triggered, and the event can be closed to prevent further operations.
90
90
91
91
92
92
@@ -150,17 +150,26 @@ Player "Alice" joined the game
<aname="ErrEventClosed"></a>ErrEventClosed is returned when an operation is attempted on a closed event.
164
+
165
+
```go
166
+
varErrEventClosed = errors.New("event is closed")
167
+
```
168
+
160
169
<aname="Event"></a>
161
-
## type [Event](<https://github.com/atomicgo/event/blob/main/event.go#L6-L10>)
170
+
## type [Event](<https://github.com/atomicgo/event/blob/main/event.go#L13-L17>)
162
171
163
-
Event represents an event system that can handle multiple listeners.
172
+
Event represents a generic, thread\-safe event system that can handle multiple listeners. The type parameter T specifies the type of data that the event carries when triggered.
Close closes the event and all its listeners. After calling this method, the event can't be used anymore and new listeners can't be added.
196
+
Close closes the event system, preventing any new listeners from being added or events from being triggered. After calling Close, any subsequent calls to Trigger or Listen will return ErrEventClosed. Existing listeners are removed, and resources are cleaned up.
Listen registers a new listener callback function for the event. The listener will be invoked with the event's data whenever Trigger is called. Returns ErrEventClosed if the event has been closed.
Trigger triggers the event and notifies all listeners.
277
+
Trigger notifies all registered listeners by invoking their callback functions with the provided value. It runs each listener in a separate goroutine and waits for all listeners to complete. Returns ErrEventClosed if the event has been closed.
269
278
270
279
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
0 commit comments