pulsar

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pulsar

type Pulsar struct {
	Period time.Duration
	// contains filtered or unexported fields
}

Pulsar is a pulsating object that generates pulses at the configured time intervals. It can be used under any piece of code that needs to periodically execute. We can use it in the followinig way:

p := pulsar.NewPulsar(1, time.Second)	// pulse every 1 second
for pulse := range p.Pulsate() {
	fmt.Println("received a pluse", pulse)
}

func NewPulsar

func NewPulsar(period int, timeUnit time.Duration) *Pulsar

NewPulsar creates a new Pulsar object and returns a pointer to it. Takes the following args:

period int: time period for the pulses
timeUnit time.Duration: the unit eg. time.MilliSecond
	time.Second etc.

func (*Pulsar) Pulsate

func (p *Pulsar) Pulsate() chan time.Time

Pulsate starts pulsating an existing pulsar. The pulses can be consumed on the returned channel.

returns a chan time.Time

func (*Pulsar) Stop

func (p *Pulsar) Stop()

Stop stops producing pulses. This would allow the calling code to be released from a block on the pulsate channel or exit the for loop ranging on the channel - whichever pattern is followed.

Jump to

Keyboard shortcuts

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