clock

package module
v0.0.0-...-7c6c06e Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2015 License: MIT Imports: 4 Imported by: 0

README

clock

A clock takes any number of strings and sends them at a somewhat consistent rate on a channel. You can specify a tick interval and a cycle duration to control how long it takes for the full set of keys to be cycled through. For example, if you use an interval of 1 second and a cycle time of 1 minute and add 120 keys, the clock will send a string on Channel 120 times per minute (2 per second on average).

Any given key will always be placed at the same position on the clock as long as the interval and cycle remain the same.

The clock can be stopped and started at any time.

package main

import (
	"fmt"
	"github.com/stvp/clock"
	"time"
)

func main() {
	c, err := clock.New(100*time.Millisecond, time.Minute, 0)
	if err != nil {
		panic(err)
	}
	c.Add("neat")
	c.Add("dude")
	c.Add("rad")
	c.Start()

	for str := range c.Channel {
		fmt.Printf("Received: %s\n", str)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	Channel chan string
	// contains filtered or unexported fields
}

func New

func New(tick, cycle time.Duration) (clock *Clock, err error)

func (*Clock) Add

func (c *Clock) Add(key string) error

func (*Clock) Keys

func (c *Clock) Keys() (keys []string)

func (*Clock) Remove

func (c *Clock) Remove(key string) error

func (*Clock) Start

func (c *Clock) Start()

func (*Clock) Stop

func (c *Clock) Stop()

Jump to

Keyboard shortcuts

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