Code Monkey home page Code Monkey logo

luna's Introduction

Tests codecov lint workflow MIT license help wanted

Luna

Luna is a flexible and generic worker pool implementation in Go, designed to manage and orchestrate workers efficiently. It supports generic types for keys and workers, allowing for a wide range of applications. Workers in the pool can be started, stopped, and have operations executed upon them, providing a robust framework for concurrent task execution.

Features

  • Generic implementation supporting any key and worker types.
  • Thread-safe operations to add, delete, and manipulate workers.
  • Error handling for start and stop operations of workers.

Installation

To install Luna, you need a working Go environment. Luna can be installed using go get:

go get github.com/kaatinga/luna

Usage

Here's a simple example of how to use Luna:

package main

import (
	"fmt"
	"github.com/kaatinga/luna"
)

type myWorker struct{}

func (myWorker) Start() error {
	fmt.Println("Worker started")
	return nil
}

func (myWorker) Stop() error {
	fmt.Println("Worker stopped")
	return nil
}

func main() {
	pool := luna.NewWorkerPool[string, myWorker]()

	if err := pool.Add("worker1", myWorker{}); err != nil {
		fmt.Printf("Error adding worker: %v\n", err)
	}

	pool.Do("worker1", func(item *luna.Item[string, myWorker]) {
		fmt.Println("Executing operation on worker")
	})

	if err := pool.Delete("worker1"); err != nil {
		fmt.Printf("Error removing worker: %v\n", err)
	}
}

Testing

To run the tests for Luna, navigate to the package directory and use the Go tool:

go test ./...

Contributing

Contributions are welcome! Please feel free to submit a pull request or open issues to discuss potential improvements or features.

License

MIT License

luna's People

Contributors

kaatinga avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.