Skip to content

About

Go package for easy work with goroutine.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

easyworker

easyworker (module github.com/manhvu/easyworker/v2) is a redesigned worker runtime for Go. It provides explicit outcomes, owned lifecycles, joinable shutdown, and separate retry and restart policies.

This version uses a clean architecture layout:

  • domain: types, policies, outcomes, errors, and logging contracts
  • runtime: supervisor, task, stream, and future orchestration
  • adapter/reflect: reflection binding and validation
  • adapter/slog: structured logging adapter
  • root package: public API facade

Requires Go 1.24 or newer.

Quick Start

ctx := context.Background()

sup, err := easyworker.NewSupervisor(ctx, easyworker.SupervisorOptions{})
if err != nil {
	log.Fatal(err)
}
defer sup.Stop(ctx)

child, err := sup.Spawn(easyworker.ChildSpec{
	Job: easyworker.MustReflect(poll, 5),
	Restart: easyworker.RestartPolicy{Mode: easyworker.RestartOnFailure},
})
if err != nil {
	log.Fatal(err)
}

_ = child

Documentation

Guides live in docs/:

Examples

Runnable samples live in examples/:

  • go run ./examples/supervisor
  • go run ./examples/task
  • go run ./examples/stream
  • go run ./examples/async

Logging

Use the structured logging adapter:

import (
	"log/slog"

	easylog "github.com/manhvu/easyworker/v2/adapter/slog"
)

sup, err := easyworker.NewSupervisor(ctx, easyworker.SupervisorOptions{
	Logger: easylog.New(slog.Default()),
})

Migration from v1

  • NewSupervisor() becomes NewSupervisor(ctx, opts).
  • NewChild plus AddChild becomes Supervisor.Spawn.
  • Stop, Done, and RemoveSupervisor become Stop(ctx) and Done().
  • NewConfig and NewTask become TaskOptions and RunTask.
  • NewStream becomes NewStream[In, Out].
  • NewGo and Monitor become Async and Future.
  • Global EnableLog becomes per-instance Logger.
  • GetSupervisor(id) is removed; capture handles directly.

MustReflect is a convenience wrapper around ReflectJob that panics on invalid construction. Use ReflectJob when construction errors must be handled. EOF

About

Go package for easy work with goroutine.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages