Skip to content

Commit

Permalink
master doc: update readme docs for option ModePath
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 14, 2023
1 parent f6dcee8 commit 6c15d5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ will trigger the execution of the `dbListener1` listener.

```go
em := event.NewManager("test", event.UsePathMode)

// register listener
em.On("app.**", appListener)
em.On("app.db.*", dbListener)
em.On("app.*.create", createListener)
em.On("app.*.update", updateListener)

// ... ...

// fire event
// TIP: will trigger appListener, dbListener, createListener
em.Fire("app.db.create", event.M{"arg0": "val0", "arg1": "val1"})
```

## Async fire events
Expand Down Expand Up @@ -339,6 +351,9 @@ event.Fire("e1", nil)
// event.FireEvent(e)
```

> **Note**: is used to add pre-defined public event information, which is added in the initialization phase, so it is not locked.
> `Event` dynamically created in business can be directly triggered by `FireEvent()`
## Gookit packages

- [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files
Expand Down
22 changes: 18 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ func doUpdate() {

```go
em := event.NewManager("test", event.UsePathMode)

// 注册事件监听器
em.On("app.**", appListener)
em.On("app.db.*", dbListener)
em.On("app.*.create", createListener)
em.On("app.*.update", updateListener)

// ... ...

// 触发事件
// TIP: 将会触发 appListener, dbListener, createListener
em.Fire("app.db.create", event.M{"arg0": "val0", "arg1": "val1"})
```

## 异步消费事件
Expand All @@ -137,10 +149,10 @@ em := event.NewManager("test", event.UsePathMode)

```go
func main() {
// 注意在,程序退出时关闭事件chan
defer event.Close()
// defer event.CloseWait()
// 注意:在程序退出时关闭事件chan
// defer event.Close()
defer event.CloseWait()

// 注册事件监听器
event.On("app.evt1", event.ListenerFunc(func(e event.Event) error {
fmt.Printf("handle event: %s\n", e.Name())
Expand Down Expand Up @@ -335,6 +347,8 @@ event.Fire("e1", nil)
// event.FireEvent(e)
```

> **Note**: `AddEvent()` 是用于添加预先定义的公共事件信息,都是在初始化阶段添加,所以没加锁. 在业务中动态创建的Event可以直接使用 `FireEvent()` 触发
## Gookit 工具包

- [gookit/ini](https://github.com/gookit/ini) INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用
Expand Down

0 comments on commit 6c15d5c

Please sign in to comment.