Replies: 2 comments 5 replies
-
Hiya! Since Greg is on vacation, I'll take a shot at a rough answer. We use thread locals mostly to keep the reactive runtimes created for each request separate from each other. Earlier Leptos versions didn't use them and instead created a separate Runtime struct for each request and stored references to it.
I don't see a reason you couldn't switch to a different primitive
…On Fri, Aug 9, 2024, at 7:26 PM, Mark Malstrom wrote:
Hello! I'm a big admirer of Leptos and everything you've accomplished with it. I've also been a long-time fan of Solid.js and fine-grained reactivity systems in general.
I'm currently attempting to implement a signals reactivity system for Swift in order to pave the way for a future SwiftWasm <https://swiftwasm.org> or AdwaitaSwift <https://www.swift.org/blog/adwaita-swift> fine-grained renderer. I figured I would try to follow the Leptos implementation as closely as possible since Swift and Rust share many traits in common. As I was working through it, I encountered this section of code <https://github.com/leptos-rs/leptos/blob/main/reactive_graph/src/graph/subscriber.rs#L5-L7>, where the global `OBSERVER` variable is created as a thread-local variable:
thread_local! {
static OBSERVER: RefCell<Option<AnySubscriber>> = const { RefCell::new(None) };
}
I've seen this technique used for the global "reactive context" variable in other languages as well, but since a Swift concurrency <https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency> compatible analog of `thread_local!` isn't available in the Swift standard library and would be complex to model from scratch, I'm curious: Why is `OBSERVER` a thread-local value instead of, say, a process-global with a lock or some other synchronization technique?
—
Reply to this email directly, view it on GitHub <#2807>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABVBTCLX6AJNMS7UW345XPTZQV25RAVCNFSM6AAAAABMJNH426VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGAZTEMBVGM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
If you don't plan to support multithreading it shouldn't matter. If you do, it does! |
Beta Was this translation helpful? Give feedback.
-
Hello! I'm a big admirer of Leptos and everything you've accomplished with it. I've also been a long-time fan of Solid.js and fine-grained reactivity systems in general.
I'm currently attempting to implement a signals reactivity system for Swift in order to pave the way for a future SwiftWasm or AdwaitaSwift fine-grained renderer. I figured I would try to follow the Leptos implementation as closely as possible since Swift and Rust share many traits in common. As I was working through it, I encountered this section of code, where the global
OBSERVER
variable is created as a thread-local variable:I've seen this technique used for the global "reactive context" variable in other languages as well, but since a Swift concurrency compatible analog of
thread_local!
isn't available in the Swift standard library and would be complex to model from scratch, I'm curious: Why isOBSERVER
a thread-local value instead of, say, a process-global with a lock or some other synchronization technique?Beta Was this translation helpful? Give feedback.
All reactions