Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sherifabdlnaby/semaphore
A fork of golang/x/sync/semaphore that is also resizable in runtime.
https://github.com/sherifabdlnaby/semaphore
go resizable semaphore semaphore-pattern
Last synced: about 18 hours ago
JSON representation
A fork of golang/x/sync/semaphore that is also resizable in runtime.
- Host: GitHub
- URL: https://github.com/sherifabdlnaby/semaphore
- Owner: sherifabdlnaby
- License: bsd-3-clause
- Created: 2019-01-17T06:39:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-04T01:00:23.000Z (almost 6 years ago)
- Last Synced: 2025-02-01T01:51:19.518Z (12 days ago)
- Topics: go, resizable, semaphore, semaphore-pattern
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Semaphore
[![](https://godoc.org/github.com/sherifabdlnaby/semaphore?status.svg)](http://godoc.org/github.com/sherifabdlnaby/semaphore)
[![Build Status](https://travis-ci.org/sherifabdlnaby/semaphore.svg?branch=master)](https://travis-ci.org/sherifabdlnaby/semaphore)
[![codecov](https://codecov.io/gh/Sherifabdlnaby/semaphore/branch/resizable-semaphore/graph/badge.svg)](https://codecov.io/gh/Sherifabdlnaby/semaphore)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)A fork of `golang/x/sync/semaphore` that is also **resizable**.
----
This fork adds the ability to resize the semaphore in a concurrent-safe way.
- Use `semaphore.Resize(N)` to resize the semaphore to a new absolute value `N`
- #### Example
```go
sem := semaphore.NewWeighted(5) // Semaphore size = 5
result1 := sem.TryAcquire(10) // returns false.
sem.Resize(15) // Semaphore size now = 10
result2 := sem.TryAcquire(10) // returns true.
fmt.Println(result1,result2) // prints false \n true
```
- Added resize functionality has **no impact on the semaphore performance** according to benchmarks.
- Tests for the newly added `Resize()` was also added.