DCPU16 Assembler in less than 200 lines of Ruby
github.com32 pointsby tophercyll20 comments
user-interface, discovery-system |
# This process is spawned with two pids as arguments
# If either pid halts, I halt too.
user-interface.link
discovery-system.link
user-interface.subscribe(when(
text-entered: { message |
# I entered a message in the UI, announce it to everyone subscribed to me
my-actor.announce('exclaimed, message)
}
))
discovery-system.subscribe(when(
peer-discovered: { name, peer |
# Discovery system located another user in the chat room
# Send message to user-interface showing a Growl style notification.
user-interface << ('notify, "{name} arrived.")
peer.subscribe(when(
# This guy went away - "halted" is announced when a process stops
halted: { result | user-interface << ('notify, "{name} left.") }
# This guy said something
exclaimed: { message | user-interface << ('text-append, "{name}: {message}") }
))
}
)
main.loop values = '[1, 2, 3]
incremented = values.map({ n | n + 1 })
summary = incremented.join(", ")
summary.starts-with?("1").then({
fail("Increment failed.")
}) When we say things such as this:
Pid = register(...),
on_exit(Pid, fun(X) -> ..),
there is a possibility the process dies in the gap between these two statements.
Regarding process death, we allow multiple inter-process relationships to be specified at spawn time. Hence any number of processes may be configured to observe a newly-spawned process before it has even started. Additionally, all children are linked to (die with) their parent, which both eliminates the risk of orphaned processes and has other benefits.
This enables some nice deployment strategies that don't require root.