mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-21 09:36:12 +08:00
use sorted-set to release stale locks
This commit is contained in:
@@ -23,9 +23,14 @@ func ExampleNewSemaphore() {
|
||||
// call sema.Close() when appropriate
|
||||
|
||||
_ = asynq.HandlerFunc(func(ctx context.Context, task *asynq.Task) error {
|
||||
if !sema.Acquire(ctx) {
|
||||
ok, err := sema.Acquire(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return &RateLimitError{RetryIn: 30 * time.Second}
|
||||
}
|
||||
|
||||
// Make sure to release the token once we're done.
|
||||
defer sema.Release(ctx)
|
||||
|
||||
|
Reference in New Issue
Block a user