Skip to content

making3/elixir_concurrency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElixirConcurrency

Demonstration / training over some Elixir concepts for iWT Health.

Tags / Commits / Notes

  1. Initial Umbrella Application
  • mix new repeater --umbrella
  1. New app
    • mix new repeater
    • Show basic testing
      • assert
      • file_name_test.exs
  2. Basic Documentation
    • parameters
    • doc tests
      • Demonstrate basic doc test failure
  3. Immutability (basic)
    • Show repeater tests
  4. Parameter guard
    • Messed up the doc test (“5” instead of 5)
    • Show iex -S mix
    • Show recompile (change Repeating to Repeat - )
  5. Parameter matching
  6. Case pattern matching
  7. Cond control structure
  8. Function matching - structs
    • Show namespace structure
  9. Basic process spawning
  • Repeater.Loop.start(“test”) - synchronous loop, “blocking”
  • Repeater.Loop.async(“foo”) - asynchronous loop
  1. Agent
  1. New Supervisor App
  • mix new chat --sup
  • Creates same app but with /lib/chat/application.ex
  1. GenServer
  • Holds state and processes
  • Note the cast / call differences
  1. Chat.Supervisor
  • Note that there isn’t a way to get the only server, somewhat useless
  1. Add :chat_room atom name to Chat.Server
  • Demonstrate in iex -S mix
    • Chat.Server.get_messages(:chat_room)
    • Chat.Server.add_message(:chat_room, “test”)
  • Demonstrate supervisor restarting
    • Process.whereis(:chat_room)
    • Process.whereis(:chat_room) |> Process.exit(:kill)
    • Process.whereis(:chat_room)
  1. Name registration from gproc & via_tuple
  • via_tuple - Tells Elixir how to use a custom registry to register our process.
  • {:via, module, term}
  • {:via, gproc, gproc parameters}
  • gproc params
    • :n - name
    • :l - local, meaning not registered on this cluster
    • {:chat_room, room_name} - actual name

Further Reading

References

About

Elixir concurrency demonstration application

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages