-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] introduce IO.withLocal (#1005)
Getting the value of a `Local` and then immediately performing a side effect is a common pattern in the codebase. See [TRef](https://github.com/getkyo/kyo/blob/9cdf197909d2ecdcd9436f5e9c687f5bbd9b5b2a/kyo-stm/shared/src/main/scala/kyo/TRef.scala#L185) as an example. Other methods like [Clock.deadline](https://github.com/getkyo/kyo/blob/9cdf197909d2ecdcd9436f5e9c687f5bbd9b5b2a/kyo-core/shared/src/main/scala/kyo/Clock.scala#L309) have a similar pattern. It currently requires two separate suspensions but that's unnecessary. The local get already suspends execution the same way as `IO` does: via the kernel's internal [Defer](https://github.com/getkyo/kyo/blob/9cdf197909d2ecdcd9436f5e9c687f5bbd9b5b2a/kyo-kernel/shared/src/main/scala/kyo/kernel/internal/Kyo.scala#L80) effect, which is the underlying suspension of `ContextEffect` and is guaranteed to be the last effect to be handled. This PR introduces `IO.withLocal` and `IO.Unsafe.withLocal` as APIs that provide both operations in a single step/allocation.
- Loading branch information
Showing
13 changed files
with
257 additions
and
128 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
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
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
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
Oops, something went wrong.