Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise FiberLocal #618

Closed
jdegoes opened this issue Mar 10, 2019 · 5 comments
Closed

Revise FiberLocal #618

jdegoes opened this issue Mar 10, 2019 · 5 comments

Comments

@jdegoes
Copy link
Member

jdegoes commented Mar 10, 2019

Copy-on-write semantics with manual or auto (fork-driven) propagation.

  1. A FiberLocal is created.
  2. Fiber A sets the value of this FiberLocal to 42.
  3. Fiber A forks another fiber, Fiber B.
  4. Fiber B reads the value of the FiberLocal and sees 42.
  5. Fiber B sets the value of the FiberLocal to 3.
  6. Fiber B reads the value of the FiberLocal and sees 3.
  7. Fiber A reads the value of the FiberLocal and sees 42.
@jdegoes
Copy link
Member Author

jdegoes commented Mar 10, 2019

It's not necessary to make fork the primitive that does propagation. One can imagine a copyOnWrite primitive:

for {
  propagate <- fiberLocal.copyOnWrite
  fiber     <- (propagate *> child).fork
} yield ...

I don't know what the API would look like. But it could be something like this, and possibly used automatically in fork, as that seems the most common use case.

@jdegoes
Copy link
Member Author

jdegoes commented Mar 10, 2019

/cc @Kaishh

@iravid
Copy link
Member

iravid commented Mar 10, 2019

yes please!!

@jdegoes
Copy link
Member Author

jdegoes commented Mar 10, 2019

@iravid What issues would this solve for you?

Basically it would solve all mine, ever. 😆

@iravid
Copy link
Member

iravid commented Mar 10, 2019

contextual logging, using the same pool for submitted Spark computations, etc...

jdegoes pushed a commit that referenced this issue May 24, 2019
* progress

* add FiberRef

* remove unsued

* scalafmt

* review fixes

* scalafmt

* More FiberRef changes

* remove synchronized

* dotty fixes

* made fiberref AnyVal

* more review fixes

* docs

* more docs update

* scalafmt

* removed unsued fiberid
@jdegoes jdegoes closed this as completed May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants