Categorygithub.com/Laisky/go-eventengine
modulepackage
0.0.0-20210729090244-abf0de2880ba
Repository: https://github.com/laisky/go-eventengine.git
Documentation: pkg.go.dev

# README

go-eventengine

License: MIT Commitizen friendly Go Report Card GoDoc Build Status codecov

simple event driven tools

Example

package main

import (
	"context"

	eventengine "github.com/Laisky/go-eventengine"
	"github.com/Laisky/go-eventengine/types"
	gutils "github.com/Laisky/go-utils"
	"github.com/Laisky/zap"
)

var closed = make(chan struct{})

func handler(evt *types.Event) error {
	gutils.Logger.Info("handler", zap.Any("event", evt))
	closed <- struct{}{}
	return nil
}

func main() {
	ctx := context.Background()

	engine, err := eventengine.New(ctx)
	if err != nil {
		gutils.Logger.Panic("new engine", zap.Error(err))
	}

	var topic types.EventTopic = "hello"

	// register handler to topic
	engine.Register(topic, handler)

	// trigger event
	engine.Publish(ctx, &types.Event{Topic: topic})

	// wait for handler to be called
	<-closed
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

GetFuncAddress get address of func.
GetHandlerID calculate handler func's address as id.
New new event store manager Args: * ctx: * WithNFork: n goroutines to run handlers in parallel * WithChanBuffer: length of channel to receive published event * WithLogger: internal logger in event engine * WithSuppressPanic: if is true, will not raise panic when running handler.
WithChanBuffer set msg buffer size of event store default to 1.
WithLogger set event store's logger default to gutils' internal logger.
WithMQ set whether suppress event handler's panic default to null.
WithNFork set nfork of event store default to 2.
WithSuppressPanic set whether suppress event handler's panic default to false.

# Structs

Type event driven engine Usage you -> produce event -> trigger multiply handlers 1.

# Interfaces

No description provided by the author

# Type aliases

Handler function to handle event.
OptFunc options for EventEngine.