Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Observer ¶
type Observer[OBJ any, ID comparable] interface { Update(data OBJ) ID() ID }
Observer 观察者.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/modes" ) type Customer struct { id int } func (p *Customer) ID() int { return p.id } func (p *Customer) Update(data string) { fmt.Printf("%d: %s\n", p.id, data) } type Sub struct { modes.Subject[string, int] } func main() { sub := &Sub{} sub.Register(&Customer{id: 1}) sub.Register(&Customer{id: 2}) sub.Notify("test1", 2) sub.NotifyAll("test2") sub.Deregister(&Customer{id: 2}) sub.Deregister(&Customer{id: 3}) sub.NotifyAll("test3") }
Output: 2: test1 1: test2 2: test2 1: test3
type Subject ¶
type Subject[OBJ any, ID comparable] struct { // contains filtered or unexported fields }
Subject 主题.
func (*Subject[OBJ, ID]) Deregister ¶
Deregister 取消注册者.
Click to show internal directories.
Click to hide internal directories.