-
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Semaphore.withPermitsIfAvailable (#3593)
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
"effect": minor | ||
--- | ||
|
||
add Semaphore.withPermitsIfAvailable | ||
|
||
You can now use `Semaphore.withPermitsIfAvailable` to run an Effect only if the | ||
Semaphore has enough permits available. This is useful when you want to run an | ||
Effect only if you can acquire a permit without blocking. | ||
|
||
It will return an `Option.Some` with the result of the Effect if the permits were | ||
available, or `None` if they were not. | ||
|
||
```ts | ||
import { Effect } from "effect" | ||
|
||
Effect.gen(function* () { | ||
const semaphore = yield* Effect.makeSemaphore(1) | ||
semaphore.withPermitsIfAvailable(1)(Effect.void) | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters