Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marusama committed Jan 18, 2018
1 parent e66277a commit 567f172
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ semaphore
[![Build Status](https://travis-ci.org/marusama/semaphore.svg?branch=master)](https://travis-ci.org/marusama/semaphore)
[![Go Report Card](https://goreportcard.com/badge/github.com/marusama/semaphore)](https://goreportcard.com/report/github.com/marusama/semaphore)
[![Coverage Status](https://coveralls.io/repos/github/marusama/semaphore/badge.svg?branch=master)](https://coveralls.io/github/marusama/semaphore?branch=master)
[![GoDoc](https://godoc.org/github.com/kamilsk/semaphore?status.svg)](https://godoc.org/github.com/marusama/semaphore)
[![GoDoc](https://godoc.org/github.com/marusama/semaphore?status.svg)](https://godoc.org/github.com/marusama/semaphore)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](LICENSE)

Fast resizable golang semaphore based on CAS

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

### Usage
Initiate
```go
import "github.com/marusama/semaphore"
...
sem := semaphore.New(5) // new semaphore with limit=5
sem := semaphore.New(5) // new semaphore with limit = 5
```
Acquire
```go
Expand Down
45 changes: 25 additions & 20 deletions semaphore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,31 @@ func checkLimitAndCount(t *testing.T, sem Semaphore, expectedLimit, expectedCoun
}

func TestNew(t *testing.T) {
sem := New(1)
checkLimitAndCount(t, sem, 1, 0)
}

func TestNew_zero_limit_panic_expected(t *testing.T) {
defer func() {
if recover() == nil {
t.Error("Panic expected")
}
}()
_ = New(0)
}

func TestNew_negative_limit_panic_expected(t *testing.T) {
defer func() {
if recover() == nil {
t.Error("Panic expected")
}
}()
_ = New(-1)
tests := []func(){
func() {
sem := New(1)
checkLimitAndCount(t, sem, 1, 0)
},
func() {
defer func() {
if recover() == nil {
t.Error("Panic expected")
}
}()
_ = New(0)
},
func() {
defer func() {
if recover() == nil {
t.Error("Panic expected")
}
}()
_ = New(-1)
},
}
for _, test := range tests {
test()
}
}

func TestSemaphore_Acquire(t *testing.T) {
Expand Down

0 comments on commit 567f172

Please sign in to comment.