
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1201 · main · 9 min 57 s
1Étoiles
0Forks
0Issues
| 1 | /// Work another node starts here (`dist.spawn_on`): a `@remote` function |
| 2 | /// is the only code a node runs on another's request. |
| 3 | |
| 4 | import std/list |
| 5 | import std/os |
| 6 | import std/process.{type Subject, type proc} |
| 7 | import std/string |
| 8 | |
| 9 | /// A text to count the words of, and where to send the count. |
| 10 | pub type Job { Job(text: String, reply: Subject<Counted>) } |
| 11 | |
| 12 | /// How many words, counted on which node. |
| 13 | pub type Counted { Counted(words: Int, node: String) } |
| 14 | |
| 15 | /// Count `job`'s words and reply. Its argument came off the wire, checked |
| 16 | /// against `Job`'s type; its reply subject is the asking node's. |
| 17 | @remote |
| 18 | pub fn count :: job: Job -> () / <proc, io> |
| 19 | { |
| 20 | let words = |
| 21 | string.split job.text " " |> list.filter fn w { w != "" } |> list.length |
| 22 | let node = match os.env "LOUISE_NODE" { Some(n) -> n, None -> "?" } |
| 23 | process.send job.reply Counted(words, node) |
| 24 | } |