Created
October 17, 2019 23:26
-
-
Save christineponyl/de69ab81f529f0b0cb06412bd3810939 to your computer and use it in GitHub Desktop.
Shared via Pony Playground (https://playground.ponylang.io/?gist=de69ab81f529f0b0cb06412bd3810939)
This file contains hidden or 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
// how to send snapshot of values from mutable container field to another actor | |
use "itertools" | |
use mut = "collections" | |
use "collections/persistent" | |
actor Receiver | |
let env: Env | |
new create(env': Env) => | |
env = env' | |
be print(li: List[I32] val) => // bc actor, parameters must be sendable | |
for item in li.values() do | |
env.out.print(item.string()) | |
end | |
actor Main | |
let _data: mut.Map[USize, List[I32]] ref = mut.Map[USize, List[I32]](8) | |
let helper: Receiver | |
let env: Env | |
new create(env': Env) => | |
env = env' | |
helper = Receiver(env) | |
helper.print(Lists[I32]([as I32: -2; -1; 0])) // test apparatus on val literal | |
go() | |
be go() => | |
try | |
_data(1234) = Lists[I32]([1;2;3;4]) | |
helper.print(_data(1234)?) | |
_data(5678) = Lists[I32]([5;6;7;8]) | |
helper.print(_data(5678)?) | |
_data(1234) = _data(1234)?.map[I32]({(x) => x + 8}) // "update" existing entry in the Map (creates a new persistent list under the covers) | |
helper.print(_data(1234)?) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment