time

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Overview

Package time contains some generic tools and helpers that are missing from the go's standard library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Refresher

type Refresher interface {
	// StartRefreshing() starts asynchronous periodic refresh of interfaces and
	// assigned IPs from the operating system
	StartRefreshing()

	// StopRefreshing() stops asynchronous periodic refresh of interfaces and
	// assigned IPs from the operating system
	StopRefreshing()

	// GetRefreshCount() returns how many times was the interfaces information
	// reloaded
	GetRefreshCount() int

	// IsRefreshing() returns true if currently the Refresher is Started
	// and running action
	IsRefreshing() bool
}

Refresher is a general thread safe periodic job runner with Start/Stop methods.

func NewRefresher

func NewRefresher(channel <-chan time.Time, action func(), refreshOnCreate, autoRefresh bool) Refresher

NewRefresher returns a new thread safe refresher, which runs action() if only it was previously Started. action() is run every time there's a new message in channel. Messages from channel are received in sequence.

func NewTickerRefresher

func NewTickerRefresher(action func(), refreshOnCreate, autoRefresh bool, autoRefreshPeriod time.Duration) Refresher

NewTickerRefresher returns a Refresher where refresh events are generated by a timed channel created with time.Ticker. It means, that if action() takes longer than refreshPeriod, refresh messages will be queued in the channel and a new action() will start immediately after the previous one ends.

Jump to

Keyboard shortcuts

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