Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-ng committed Nov 24, 2020
1 parent abde4ba commit a3c9b0f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ timeouts and dynamic priority of goroutines.

```go
nl := limiter.New(3)
nl.Wait()
ctx := context.Background()
nl.Wait(ctx)
Execute......
nl.Finish()
```
In the above example , there can be a maximum of 3 goroutines accessing a resource concurrently. The other goroutines are added to the waiting list and are removed and given a
chance to access the resource in the FIFO order.
chance to access the resource in the FIFO order. If the context is cancelled , the goroutine is removed from the waitlist.

### Limiter with Timeout

```go
nl := limiter.New(3,
WithTimeout(10),
)
nl.Wait()
ctx := context.Background()
nl.Wait(ctx)
Execute......
nl.Finish()
```
Expand All @@ -39,7 +41,8 @@ number of concurrent goroutines is greater than the limit specified.

```go
nl := priority.NewLimiter(3)
nl.Wait(priority.High)
ctx := context.Background()
nl.Wait(ctx , priority.High)
Execute......
nl.Finish()
```
Expand All @@ -53,7 +56,8 @@ given the maximum preference because it is of high priority. In the case of tie
nl := priority.NewLimiter(3,
WithDynamicPriority(5),
)
nl.Wait(priority.Low)
ctx := context.Background()
nl.Wait(ctx , priority.Low)
Execute......
nl.Finish()
```
Expand All @@ -64,9 +68,13 @@ In Dynamic Priority Limiter , the goroutines with lower priority will get their
```go
nl := priority.NewLimiter(3,
WithTimeout(30),
WithDynamicPriority(5),
)
nl.Wait(priority.Low)
ctx := context.Background()
nl.Wait(ctx , priority.Low)
Execute......
nl.Finish()
```
This is similar to the timeouts in the normal limiter. In the above example , goroutines will wait a maximum of 30 milliseconds.
This is similar to the timeouts in the normal limiter. In the above example , goroutines will wait a maximum of 30 milliseconds. The low priority goroutines will get their
priority increased every 5 ms.

0 comments on commit a3c9b0f

Please sign in to comment.