goevent

package
v1.2.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-event 基于 chan

观察者模式 事件中心
扩展开发,定义消息通道大小
//使用方法
package main

import (
	goevent "github.com/gif-gif/go.io/go-event"
	golog "github.com/gif-gif/go.io/go-log"
	"github.com/gif-gif/go.io/goio"
	"time"
)

func main() {
	goio.Init()
	event := goevent.New()
	event.Subscribe("test", func(msg goevent.Message) {
		golog.WithTag("goevent").Info(msg)
	})
	event.Publish("test", "test")
	time.Sleep(time.Duration(1) * time.Second)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(topic string, data interface{})

func Subscribe

func Subscribe(topic string, fn SubscribeFunc)

Types

type GoEvent added in v1.1.8

type GoEvent struct {
	DefaultTopic string
	// contains filtered or unexported fields
}

func Default

func Default() *GoEvent

func New

func New(channelSize ...int) *GoEvent

func (*GoEvent) Publish added in v1.1.8

func (ev *GoEvent) Publish(topic string, data interface{})

发布 执行当前topic 对应的所有订阅者

func (*GoEvent) Subscribe added in v1.1.8

func (ev *GoEvent) Subscribe(topic string, fn SubscribeFunc)

订阅:一个topic可以对应多个处理器,(topic->handler 的关系是1:n),一次添加一个订阅者

func (*GoEvent) UnSubscribe added in v1.1.8

func (ev *GoEvent) UnSubscribe(topic string)

func (*GoEvent) UnSubscribeDefault added in v1.2.34

func (ev *GoEvent) UnSubscribeDefault()

type Message

type Message struct {
	Topic string
	Data  interface{}
}

type MessageChan

type MessageChan chan Message

type SubscribeFunc

type SubscribeFunc func(msg Message)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL