UHub

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: MIT Imports: 4 Imported by: 0

README

UHub

universal subscriber and publisher


package main

import (
	"fmt"

	"github.com/coreservice-io/UHub"
)

const testKind UHub.Kind = 1

type testEvent string

func (e testEvent) Kind() UHub.Kind {
	return testKind
}

func main() {

	var h UHub.Hub

	h.Subscribe(testKind, func(e UHub.Event) {
		fmt.Println("subcallback")
		fmt.Println(string(e.(testEvent)))
	})
	h.Publish(testEvent("this is example"))

}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetSeed added in v0.0.2

func ResetSeed()

Types

type Event

type Event interface {
	Kind() Kind
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func (*Hub) Publish

func (h *Hub) Publish(e Event)

Publish an event to the subscribers.

func (*Hub) Subscribe

func (h *Hub) Subscribe(kind Kind, f func(Event)) (cancel func())

Subscribe registers f for the event of a specific kind.

type Kind

type Kind int64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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