3 ms·
> functions with captured variable serialization Can't wait for the deep dive on how that works
by jrmiii 3y ago
> functions with captured variable serialization
Can't wait for the deep dive on how that works
- azurelake 3y agoProbably not too much to say that’s specific to FLAME. Closures are serializable and can be sent as messages to actors on the BEAM with a few caveats. From a quick look at the code, this looks the magic line: https://github.com/phoenixframework/flame/blob/main/lib/flame/runner.ex#L407-L408 https://github.com/phoenixframework/flame/blob/main/lib/flam...
- quaunaut 3y agoThat's just standard erlang/elixir- because all values are immutable, when a new anonymous function is defined it copies the current value of the external variables into it. You can do it right now even without Flame, just by opening two Elixir nodes, then it's as simple as ```elixir iex(first_node@localhost)> name = "Santa" iex(first_node@localhost)> Node.spawn_link(:other_node@localhost, fn -> IO.puts "Hello #{name}" end) Hello Santa #PID<1337.42.0> ``` Note that while the string interpolation and `IO.puts` was run on `other_node@localhost`, it still did stdout from the first node- this is because it was the one that called `Node.spawn_link`, making it the 'group leader'. Outside of which stdout it went to, all the work was done in the other node.