Skip to content

Commit

Permalink
docs: 更新示例代码
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Oct 6, 2022
1 parent d4ef343 commit 83a5526
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ events
简单的事件订阅发布系统

```go
p, e := events.New()
e := events.New[string]()

e.Attach(sub1)
e.Attach(sub2)

p.Publish(true, "触发事件1") // sub1 和 sub2 均会收事事件
e.Publish(true, "触发事件1") // sub1 和 sub2 均会收事事件
```

安装
Expand Down
12 changes: 6 additions & 6 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

// Package events 提供了简单的事件发布订阅功能
//
// p, e := events.New()
// e := events.New[string]()
//
// // 订阅事件
// e.Attach(func(data interface{}){
// fmt.Println("subscriber 1")
// e.Attach(func(data string){
// fmt.Println("subscriber 1:", data)
// })
//
// // 订阅事件
// e.Attach(func(data interface{}){
// fmt.Println("subscriber 2")
// e.Attach(func(data string){
// fmt.Println("subscriber 2:", data)
// })
//
// p.Publish(true, nil) // 发布事件
// e.Publish(true, "test") // 发布事件
package events

import (
Expand Down

0 comments on commit 83a5526

Please sign in to comment.