churncore

package
v0.0.0-...-dc7ae07 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example
ch := make(chan string)
sender, err := NewSender(ch)
if err != nil {
	fmt.Println(err)
}

receiver, err := NewReceiver(func(msg string) {
	fmt.Println(msg)
})
if err != nil {
	fmt.Println(err)
}

subs, err := sender.Subscribe(receiver)
if err != nil {
	fmt.Println(err)
}

ch <- "Hello, World!"
ch <- "MESSAGE2"

time.Sleep(time.Millisecond) // allow the singnals to propagate
subs.Close()
close(ch)
Output:

Hello, World!
MESSAGE2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Receiver

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

Receiver represents a function that can handle messages of a specific go data type

func NewReceiver

func NewReceiver(handlerFunc interface{}) (*Receiver, error)

NewReceiver creates a message receiver from the given function. 'handlerFunc' must take a single parameter of the desired message data type and may return nothing, or a single error, as required

type Sender

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

Sender produces messages that can be handled by receivers

func NewSender

func NewSender(channel interface{}) (*Sender, error)

NewSender creates a new message sender using the given go channel. 'channel' must be receive-able, and the returned Sender will continually consume all channel values until the channel is closed

func (*Sender) Subscribe

func (s *Sender) Subscribe(r *Receiver) (*Subscription, error)

Subscribe creates a subscription from this sender to the given receiver, which will cause the receiver's underlying function to be called for every sent value until the subscription is closed

type Subscription

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

Subscription connects a sender to a compatible receiver and manages the transfer of messages between them

func (*Subscription) Close

func (s *Subscription) Close()

Close ends this subscription

Jump to

Keyboard shortcuts

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