Free Nulled Content Timeline Download v4.4.3
Free Nulled MayaShop Download v3.1.1

Introducing Elixir by Simon St.Laurent & J. David Eisenberg

Introducing Elixir by Simon St.Laurent & J. David Eisenberg

Author:Simon St.Laurent & J. David Eisenberg
Language: eng
Format: epub
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.


Copyright Disclaimer:
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.