10. Actors
10. Actors
Section titled “10. Actors”Canonical source:
protos/tutorials/10-actors/at locked revisione99b712ecf658a527b1fe82c8beba2c1286d8dc9.
These are the executable tutorial sources from the exact Protos revision consumed by this website. The fenced program bodies are copied without modification. The tutorials are explanatory and non-normative; the applicable specification remains authoritative.
01 — Current actor
Section titled “01 — Current actor”Canonical source protos/tutorials/10-actors/01-current-actor.protos
/* * THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE * ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC * DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF * DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE * OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF * THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY * OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING * THE CONTENTS OF THIS FILE. */
// Actor.current() returns the stable ActorRef for this incarnation.me: Actor.current()print(me === Actor.current())02 — Spawn and request
Section titled “02 — Spawn and request”Canonical source protos/tutorials/10-actors/02-spawn-and-request.protos
/* * THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE * ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC * DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF * DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE * OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF * THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY * OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING * THE CONTENTS OF THIS FILE. */
// Actor.spawn identifies destination-loadable module code plus a bootstrap binding.// std:collections/Set.call returns an ordinary Map, which becomes this Actor's behavior.worker: Actor.spawn("std:collections/Set", "call", 1, 2, 3)print(worker.request("size").value())worker.stop()03 — Send and lifecycle
Section titled “03 — Send and lifecycle”Canonical source protos/tutorials/10-actors/03-send-and-lifecycle.protos
/* * THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE * ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC * DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF * DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE * OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF * THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY * OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING * THE CONTENTS OF THIS FILE. */
worker: Actor.spawn("std:collections/Set", "call")finished: worker.termination()
// send does not return the handler result. The following request is issued by the// same Actor to the same concrete destination, so it cannot overtake this send.worker.send("atPut", "ready", true)print(worker.request("size").value())
worker.stop()print(finished.value() === worker)