Skip to content

Commit

Permalink
docs: autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Sep 12, 2024
1 parent eaf9942 commit 2e76456
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
import "atomicgo.dev/event"
```

Package event provides a generic event system for Go.
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.



Expand Down Expand Up @@ -150,17 +150,26 @@ Player "Alice" joined the game

## Index

- [Variables](<#variables>)
- [type Event](<#Event>)
- [func New\[T any\]\(\) \*Event\[T\]](<#New>)
- [func \(e \*Event\[T\]\) Close\(\)](<#Event[T].Close>)
- [func \(e \*Event\[T\]\) Listen\(f func\(T\)\)](<#Event[T].Listen>)
- [func \(e \*Event\[T\]\) Trigger\(value T\)](<#Event[T].Trigger>)
- [func \(e \*Event\[T\]\) Listen\(f func\(T\)\) error](<#Event[T].Listen>)
- [func \(e \*Event\[T\]\) Trigger\(value T\) error](<#Event[T].Trigger>)


## Variables

<a name="ErrEventClosed"></a>ErrEventClosed is returned when an operation is attempted on a closed event.

```go
var ErrEventClosed = errors.New("event is closed")
```

<a name="Event"></a>
## type [Event](<https://github.com/atomicgo/event/blob/main/event.go#L6-L10>)
## type [Event](<https://github.com/atomicgo/event/blob/main/event.go#L13-L17>)

Event represents an event system that can handle multiple listeners.
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.

```go
type Event[T any] struct {
Expand All @@ -169,22 +178,22 @@ type Event[T any] struct {
```

<a name="New"></a>
### func [New](<https://github.com/atomicgo/event/blob/main/event.go#L13>)
### func [New](<https://github.com/atomicgo/event/blob/main/event.go#L20>)

```go
func New[T any]() *Event[T]
```

New creates a new event.
New creates and returns a new Event instance for the specified type T.

<a name="Event[T].Close"></a>
### func \(\*Event\[T\]\) [Close](<https://github.com/atomicgo/event/blob/main/event.go#L64>)
### func \(\*Event\[T\]\) [Close](<https://github.com/atomicgo/event/blob/main/event.go#L74>)

```go
func (e *Event[T]) Close()
```

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.
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.



Expand Down Expand Up @@ -250,22 +259,22 @@ func main() {


<a name="Event[T].Listen"></a>
### func \(\*Event\[T\]\) [Listen](<https://github.com/atomicgo/event/blob/main/event.go#L35>)
### func \(\*Event\[T\]\) [Listen](<https://github.com/atomicgo/event/blob/main/event.go#L58>)

```go
func (e *Event[T]) Listen(f func(T))
func (e *Event[T]) Listen(f func(T)) error
```

Listen gets called when the event is triggered.
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.

<a name="Event[T].Trigger"></a>
### func \(\*Event\[T\]\) [Trigger](<https://github.com/atomicgo/event/blob/main/event.go#L21>)
### func \(\*Event\[T\]\) [Trigger](<https://github.com/atomicgo/event/blob/main/event.go#L27>)

```go
func (e *Event[T]) Trigger(value T)
func (e *Event[T]) Trigger(value T) error
```

Trigger triggers the event and notifies all listeners.
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.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

Expand Down

0 comments on commit 2e76456

Please sign in to comment.