pooler

package module
v0.1.0-1642873533118264 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 6 Imported by: 0

README

pooler

Tricky and fun utilities for Go programs.


GitHub Workflow Status Codecov

Contributor Covenant

Twitter Follow GitHub followers


Getting Started

Prerequisites

Developed with $( go version; ). Go is extremely backwards compatible and semver stable. Nearly any v1.x should work fine.


Installation

To use this repo as a template for your own project:

gh repo create -y --public --template "https://github.com/skeptycal/pooler"

Clone this repo to test and contribute:

# add repo to $GOPATH (xxxxxx is your computer login username)
go get github.com/xxxxxx/pooler

cd ${GOPATH}/src/github.com/xxxxxx/pooler

# test results and coverage info
./go.test.sh

# install as a utility package
go install

Use the Issues and PR templates on the GitHub repo page to contribute.


Basic Usage

This is a copy of the example script available in the cmd/example/pooler folder:

package main

import "github.com/skeptycal/pooler"

func main() {
    pooler.Example()
}

To try it out:

# change to the sample folder
cd cmd/example/pooler

# run the main.go program
go run ./main.go

# to compile as an executable
go build

Code of Conduct and Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. Please read the Code of Conduct for details before submitting anything.


Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.


Contributors and Inspiration

  • Michael Treanor (GitHub / Twitter) - Initial work, updates, maintainer
  • Francesc Campoy - Inspiration and great YouTube videos!

See also the list of contributors who participated in this project.


License

Licensed under the MIT https://opensource.org/licenses/MIT - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEBUG bool = false
View Source
var WorkerChannel = make(chan chan Work)

Functions

func CreateExampleJobs

func CreateExampleJobs(amount int) []string

CreateExampleJobs mimics the creation of 'amount' concurrent jobs.

func CreateJobs

func CreateJobs(amount int, js JobSpec) []string

CreateExampleJobs mimics the creation of 'amount' concurrent jobs.

func DoWork

func DoWork(word string, id int)

DoWork mimics any type of job that can be run concurrently

func Example

func Example()

func RandStringRunes

func RandStringRunes(n int) string

Types

type Any

type Any interface{}

type Collector

type Collector struct {
	Work chan Work
	End  chan bool
}

func StartDispatcher

func StartDispatcher(workerCount int) Collector

type JobSpec

type JobSpec interface {

	// Identifier is the main unique identifier associated
	// with this specific job specification. It may be
	// considered analogous to a primary key in a database.
	Identifier() Any

	// Name is an optional text name for this job that will
	// be used in error messages and reports.
	Name() string

	// ID is an optional unique identifier for this job. It
	// may be used when sorting and searching performance
	// will be hindered by using an interface{}.
	Id() int

	// Completed tags the job specification as completed.
	// Not all workers may have finished, but the goals of
	// the job specification have been reached. All work is
	// stopped and no further work will be performed.
	Completed() bool

	// Deadline is an optional time at which the job spec
	// expires and no more work will be performed towards
	// the goals of this job specification.
	Deadline() time.Time
}

type Work

type Work struct {
	ID  int
	Job string
	JS  JobSpec
}

type Worker

type Worker interface {
	Start()
	Stop()
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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