background

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: ISC Imports: 0 Imported by: 3

Documentation

Overview

Simple skeleton for background processes

Example
package main

import (
	"fmt"
	"github.com/bitmark-inc/bitmarkd/background"
	"time"
)

type theState struct {
	count int
}

func main() {

	proc := &theState{
		count: 10,
	}

	// list of background processes to start
	var processes = background.Processes{
		proc,
	}

	p := background.Start(processes, nil)
	time.Sleep(time.Second)
	p.Stop()
}

func (state *theState) Run(args interface{}, shutdown <-chan struct{}) {

	fmt.Printf("initialise\n")

loop:
	for {
		select {
		case <-shutdown:
			break loop
		default:
		}

		state.count += 1
		time.Sleep(time.Millisecond)
	}

	fmt.Printf("finalise\n")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

type Process interface {
	Run(args interface{}, shutdown <-chan struct{})
}

type signature for background process and type that implements this Run is a process

type Processes

type Processes []Process

list of processes to start

type T

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

handle type for the stop

func Start

func Start(processes Processes, args interface{}) *T

start up a set of background processes all with the same arg value

func (*T) Stop added in v0.2.0

func (t *T) Stop()

stop a set of background processes

Jump to

Keyboard shortcuts

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