Skip to content

Push Components replace the need for golang chan and select constructs, which require no polling and are instead designed to "push" new work to the client when available.

License

Notifications You must be signed in to change notification settings

blocktop/go-push-components

Repository files navigation

go-push-components

standard-readme compliant

Push Components replace the need for golang chan and select constructs, which require no polling and are instead designed to "push" new work to the client when available.

Table of Contents

Background

A common golang idiom when a component needs to receive messages from another component is to poll a chan using a select loop. In this construct, the message sender publishes to the chan and the receiver pulls from it. chan is a bare-bones component. It does not manage concurrency and it requires continuous CPU work by the receiver for the polling the chan.

Push Components decouple the sender and receiver, as chan does, but it also helpfully manages other aspects of such an exchange pattern:

  • concurrency
  • overload
  • drain, and graceful shutdown
  • counting items in the component
  • emptying the component

Push Components provided in this package:

  • PushQueue
  • PushStack

Install

go get -u github.com/blocktop/go-push-components

Usage

Create the push component (in this case a queue), tell it concurrency and capacity attributes, and provide a worker function.

q := push.NewPushQueue(2, 50, worker)
q.Start()
   
func worker(item Item) {
  doWorkWithItem(item)
}

API

Maintainers

@strobus

Contribute

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2018 J. Strobus White

About

Push Components replace the need for golang chan and select constructs, which require no polling and are instead designed to "push" new work to the client when available.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages