runner

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 4 Imported by: 1

README

runner - A module for starting and stopping servers and background jobs

GoDoc Go Report Card

Documentation

Overview

Package runner provides means for starting and stopping servers and background jobs.

Example
package main

import (
	"log"

	"github.com/jasonhancock/runner"
)

type myServer struct{}

func (s *myServer) Run() error {
	log.Println("starting...")
	return nil
}

func (s *myServer) Stop() error {
	log.Println("stopping...")
	return nil
}

func main() {
	// create a context that will be cancelled when an os signal tells the process to shut down.
	ctx := runner.Context()

	// Fire up some background job that will shutdown when ctx is cancelled.
	go func() {
		// some background job....
		<-ctx.Done()
	}()

	// start up a server. This call will block.
	runner.RunServer(&myServer{})
}

Index

Examples

Constants

This section is empty.

Variables

Signals defines the list of signals that will cause the server to shutdown

Functions

func Context

func Context() context.Context

Context returns a context that will be cancelled when a signal is received to shut down.

func RunServer

func RunServer(server Server) error

RunServer starts up a Server, then blocks until a signal is received to shut down at which time the Server's Stop() method is called

Types

type Server

type Server interface {
	Run() error
	Stop() error
}

Server defines a runable interface. The Run() method should not block (any background tasks should be run in goroutines)

Jump to

Keyboard shortcuts

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