Skip to content

consyse/distsemaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

distributedsemaphore

License

Fast distributed & resizable golang semaphore based on CAS.

  • allows weighted acquire/release;
  • supports cancellation via context;
  • allows change semaphore limit after creation;
  • faster than channel based semaphores.

Based off of github.com/marusama/semaphore

Usage

Initiate

import "github.com/consyse/semaphore"
...
sem := semaphore.New(5) // new semaphore with limit = 5

Acquire

sem.Acquire(ctx, n)     // acquire n with context
sem.TryAcquire(n)       // try acquire n without blocking 
...
ctx := context.WithTimeout(context.Background(), time.Second)
sem.Acquire(ctx, n)     // acquire n with timeout

Release

sem.Release(n)          // release n

Change semaphore limit

sem.SetLimit(new_limit) // set new semaphore limit

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages