The implementation of the pattern observer

Event

Build Status codecov Go Report Card GoDoc

This is package implements pattern-observer

Fast example

import (
	"github.com/agoalofalife/event"
)

func main() {
	// create struct
	e := event.New()

	// subscriber 
	e.Add("push.email", func(text string){
    	// some logic 
    }, "text")
    
    // init event
    e.Fire("push.email") // or e.Go("push.email")
}

let us consider an example:

  • You must first create the structure
  • Next, the first argument declares the name of the event (string type), second argument executes when the event occurs, the third argument is passed a list of arguments, which are substituted in the parameters of the second argument.
  • In the end you need to run the event. There are two methods available "Go" and his alias "Fire"

The subscriber function method

type Email struct {
	count int
}
func (e *Email) Push() {
	e.count += 1
	fmt.Printf("Push email again, count %d \n", e.count)
}
func main() {
	e := event.New()
	
	email := new(Email)
	
	e.Add(email, email.Push)
	e.Fire(email)
	e.Fire(email)
}
// output 
// Push email again, count 1 
// Push email again, count 2 

Bench

// create struct and add new event handler
BenchmarkAdd-8           1000000              1482 ns/op

// create struct and add new event handler and N run this handler
BenchmarkGo-8            5000000               339 ns/op

  • In this example we sign the event method structure

Read more information in examples 👍

Owner
Ilya
You can learn anything
Ilya
Similar Resources

Observer-pattern is broken at GitHub, too many mails

Informer What Returns information at your will. Should enable you to turn off all notifications, without loosing important notices. Format should be y

Jan 21, 2022

State observer - StateObserver used to synchronize the local(cached) state of the remote object with the real state

state observer StateObserver used to synchronize the local(cached) state of the

Jan 19, 2022

Observer - Golang event dispatch

observer go基于观察者模式的事件调度 Installation go get -u github.com/caijw-go/observer Usa

Jan 22, 2022

Go-ant-pattern: An ant pattern parser

go-ant-pattern - An ant pattern parser. Usage package main import ( "fmt" "github.com/cbuschka/go-ant-pattern" ) func main() { path := "

Dec 7, 2021

Leader-follower-pattern - Build leader-follower system pattern with etcd election

主备系统模式 原理 使用分布式锁实现主备节点系统。通过对分布式锁进行续期,保持长期锁, 从而使当前服务节点处于主服务节点 无法获取分布式锁的服务节点,则作为备选

Jan 24, 2022

Go implementation of Fowler's Money pattern

Go implementation of Fowler's Money pattern

Money GoMoney provides ability to work with monetary value using a currency's smallest unit. This package provides basic and precise Money operations

Jan 3, 2023

🚦 Semaphore pattern implementation with timeout of lock/unlock operations.

🚦 Semaphore pattern implementation with timeout of lock/unlock operations.

🚦 semaphore Semaphore pattern implementation with timeout of lock/unlock operations. 💡 Idea The semaphore provides API to control access to a shared

Dec 7, 2022

An efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern.

An efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern.

Circuit Circuit is an efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern. Learn more about the problems Hyst

Dec 28, 2022

A go library that facilitates the implementation of decorator pattern.

go-decorator go-decorator is a library that facilitates the implementation of decorator pattern. Installation To install go-decorator, use go get: go

Nov 25, 2021

Go language implementation of a blockchain based on the BDLS BFT protocol. The implementation was adapted from Ethereum and Sperax implementation

BDLS protocol based PoS Blockchain Most functionalities of this client is similar to the Ethereum golang implementation. If you do not find your quest

Oct 14, 2022

Multi-String Pattern Matching Algorithm Using TrieHashNode

Multi-String Pattern Matching algorithm. This implementation is inspired from Aho-Corasick algorithm Getting Started modelA = mspm.NewModel("mspm_mode

Dec 9, 2022

A library that implements the outboxer pattern in go

Outboxer Outboxer is a go library that implements the outbox pattern. Getting Started Outboxer was designed to simplify the tough work of orchestratin

Dec 16, 2022

:incoming_envelope: A fast Message/Event Hub using publish/subscribe pattern with support for topics like* rabbitMQ exchanges for Go applications

Hub 📨 A fast enough Event Hub for go applications using publish/subscribe with support patterns on topics like rabbitMQ exchanges. Table of Contents

Dec 17, 2022

skipmap is a high-performance concurrent sorted map based on skip list. Up to 3x ~ 10x faster than sync.Map in the typical pattern.

skipmap is a high-performance concurrent sorted map based on skip list. Up to 3x ~ 10x faster than sync.Map in the typical pattern.

Introduction skipmap is a high-performance concurrent map based on skip list. In typical pattern(one million operations, 90%LOAD 9%STORE 1%DELETE), th

Jan 8, 2023

A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

A pluggable "Application State Gateway" that enforces the Event Sourcing Pattern for securely persisting & broadcasting application state ch

Nov 1, 2022

A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

A pluggable "Application State Gateway" that enforces the Event Sourcing Pattern for securely persisting & broadcasting application state changes

Nov 1, 2022

Create a cool glass-like pattern using Voronoi cells

Create a cool glass-like pattern using Voronoi cells

voronoi-glass Have you ever looked through a shower door made of intentionally uneven glass? Everything looks distorted, but maybe also beautiful. Now

Jul 21, 2022

Create production ready microservices mono repo pattern wired with Neo4j. Microservices for other languages and front end repos to be added as well in future.

Create production ready microservices mono repo pattern wired with Neo4j. Microservices for other languages and front end repos to be added as well in future.

Create Microservices MonoRepo in GO/Python Create a new production-ready project with backend (Golang), (Python) by running one CLI command. Focus on

Oct 26, 2022

An extension for discordgo to create a Discord bot quickly using the Builder pattern.

botbuilder An extension for discordgo to create a Discord bot quickly using the Builder pattern. Example usage: package main import ( "log" "os"

Oct 12, 2022
Apr 12, 2022
graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

Dec 5, 2022
🔊Minimalist message bus implementation for internal communication

?? Bus Bus is a minimalist event/message bus implementation for internal communication. It is heavily inspired from my event_bus package for Elixir la

Jan 3, 2023
Package notify provides an implementation of the Gnome DBus Notifications Specification.

go-notify Package notify provides an implementation of the Gnome DBus Notifications Specification. Examples Display a simple notification. ntf := noti

Dec 27, 2022
mangos is a pure Golang implementation of nanomsg's "Scalablilty Protocols"
mangos is a pure Golang implementation of nanomsg's

mangos Mangos™ is an implementation in pure Go of the SP (“Scalability Protocols”) messaging system. These are colloquially known as a “nanomsg”. ❗ Th

Jan 1, 2023
Server-sent live updates: protocol and reference implementation
Server-sent live updates: protocol and reference implementation

Protocol and Reference Implementation Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast

Jan 1, 2023
Implementation of the NELI leader election protocol for Go and Kafka
Implementation of the NELI leader election protocol for Go and Kafka

goNELI Implementation of the NELI leader election protocol for Go and Kafka. goNELI encapsulates the 'fast' variation of the protocol, running in excl

Dec 8, 2022
Embedded, Fast and Persistent bigqueue implementation

bigqueue bigqueue provides embedded, fast and persistent queue written in pure Go using memory mapped (mmap) files. bigqueue is now thread safe as wel

Sep 24, 2022
ChizBroker is a fast and simple GRPC based implementation of kafka.
ChizBroker is a fast and simple GRPC based implementation of kafka.

Chiz Broker: a broker for fun ChizBroker is a fast and simple GRPC based implementation of kafka. Features: Ready to be deployed on kubernetes Prometh

Oct 30, 2022
POC of an event-driven Go implementation

Event Driven example in Golang This POC shows an example of event-driven architecture with a working domain event broker, an event producer and a cons

Nov 2, 2021