-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ffcb8e
commit 0b88c01
Showing
4 changed files
with
36 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
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
21 changes: 21 additions & 0 deletions
21
core/shared/src/main/scala/cats/effect/unsafe/IOLocals.scala
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 @@ | ||
package cats.effect | ||
package unsafe | ||
|
||
// TODO handle defaults and lenses. all do-able, just needs refactoring ... | ||
final class IOLocals private[effect] (private[this] var state: IOLocalState) { | ||
|
||
private[effect] def getState(): IOLocalState = state | ||
|
||
def get[A](iol: IOLocal[A]): A = state(iol).asInstanceOf[A] | ||
|
||
def set[A](iol: IOLocal[A], value: A): Unit = state += (iol -> value) | ||
|
||
def reset[A](iol: IOLocal[A]): Unit = state -= iol | ||
|
||
// TODO other ops from IOLocal | ||
|
||
} | ||
|
||
object IOLocals { | ||
val threadLocal = ThreadLocal.withInitial[IOLocals](() => null) | ||
} |