futureevent

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package futureevent defines interface to handle future events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	// Chan returns a channel which this Event notifies of the occurrence.
	// The time.Time value represents the time of the occurrence.
	//
	// Remember that the event may be canceled, in which case the channel
	// gets closed and empty. The listeners can detect the cancelation by
	// checking the boolean result of a receive operation.
	Chan() <-chan time.Time

	// Cancel cancels the event.
	//
	// Cancel clears and closes the event notifier channel, thus must not be
	// called more than once.
	Cancel()
}

Event represents a cancelable event that occurs sometime in future.

func NewRealClockEvent

func NewRealClockEvent(at time.Time) Event

NewRealClockEvent returns a new Event kicked at the provided Time, using the real clock.

func OnSignal

func OnSignal(sig os.Signal) Event

OnSignal returns a new Event kicked on sig.

type Factory

type Factory func(t time.Time) Event

Factory creates a new Event raised when the provided time t comes.

var DefaultFactory Factory = NewRealClockEvent

DefaultFactory uses the real clock.

type NeverOccursEvent

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

NeverOccursEvent never occurs. It is still cancelable.

func NeverOccurs

func NeverOccurs() *NeverOccursEvent

NeverOccurs creates a new NeverOccursEvent.

func (*NeverOccursEvent) Cancel

func (e *NeverOccursEvent) Cancel()

Cancel unblocks the receive operation on e.Chan().

func (*NeverOccursEvent) Chan

func (e *NeverOccursEvent) Chan() <-chan time.Time

Chan returns an event notifier channel. Since the event never occurs, the receive operation on the returned channel would be blocked until e is canceled.

type TriggerableEvent

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

TriggerableEvent is an Event triggered by a method call.

func NewTriggerableEvent

func NewTriggerableEvent() *TriggerableEvent

NewTriggerableEvent creates a new TriggerableEvent.

func (*TriggerableEvent) Cancel

func (e *TriggerableEvent) Cancel()

Cancel makes e no longer triggerable.

func (*TriggerableEvent) Chan

func (e *TriggerableEvent) Chan() <-chan time.Time

Chan returns the event notifier channel.

func (*TriggerableEvent) Trigger

func (e *TriggerableEvent) Trigger()

Trigger triggers the event.

Jump to

Keyboard shortcuts

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