Introducing Elixir by Simon St.Laurent & J. David Eisenberg
Author:Simon St.Laurent & J. David Eisenberg
Language: eng
Format: epub, mobi
Publisher: O'Reilly Media, Inc.
Published: 2017-01-11T05:00:00+00:00
Example 9-7. Calling a process from a process, and reporting the results
defmodule MphDrop do def mph_drop do drop_pid = spawn(Drop, :drop, []) convert(drop_pid) end def convert(drop_pid) do receive do {planemo, distance} -> send(drop_pid, {self(), planemo, distance}) convert(drop_pid) {planemo, distance, velocity} -> mph_velocity = 2.23693629 * velocity IO.write("On #{planemo}, a fall of #{distance} meters ") IO.puts("yields a velocity of #{mph_velocity} mph.") convert(drop_pid) end end end
The mph_drop/1 function spawns a Drop.drop/0 process when it is first set up, using the same module you saw in Example 9-6, and stores the pid in drop_pid. Then it calls convert/1, which will listen for messages recursively.
Download
Introducing Elixir by Simon St.Laurent & J. David Eisenberg.mobi
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(26289)
Hello! Python by Anthony Briggs(25214)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(24445)
Kotlin in Action by Dmitry Jemerov(23533)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(22877)
Dependency Injection in .NET by Mark Seemann(22666)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21428)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20272)
Grails in Action by Glen Smith Peter Ledbrook(19342)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17054)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16365)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14077)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12254)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11530)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10643)
Hit Refresh by Satya Nadella(9219)
The Kubernetes Operator Framework Book by Michael Dame(8579)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8432)
Robo-Advisor with Python by Aki Ranin(8376)