-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduction to Processes guide #4
base: master
Are you sure you want to change the base?
Conversation
Processes.md
Outdated
Using add_item we are modifying the state and all shows the maintenance of our system state, i.e you can add as many | ||
items and the length of the state is maintained, which in our case is a list of 3 items so far. | ||
|
||
With the steps shown above, the chef can instantly perform updates and maintain the state of the menu, which the customer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the steps shown above, the restaurant is able to instantly perform updates and maintain the state of its menu, which the customer will then use to place their orders and eliminate the need of waiting for someone to take your order.
Processes.md
Outdated
|
||
Recently when I was working on Elixir processes, I remembered the restaurant incident and I thought, | ||
processes can be used to hold state. Therefore, a restaurant menu can always be availed to customers on their table | ||
(perhaps using a screen on the table), with the new delicacies/meals of the day list. The customers would then be able |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(perhaps using a screen on the table or the restaurants mobile app)
Processes.md
Outdated
processes can be used to hold state. Therefore, a restaurant menu can always be availed to customers on their table | ||
(perhaps using a screen on the table), with the new delicacies/meals of the day list. The customers would then be able | ||
to place orders directly to the kitchen, which would take way much less time. This would mean that the menu list has to | ||
be flawless and everything listed on it should be available and the restaurant would have a way of tracking orders made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean that the menu list has to be up to date with that exists in the kitchen stock inventory with every order updating the state appropriately.
Processes.md
Outdated
Maintain state. | ||
|
||
|
||
Let’s create a module Menuprocess.ex and see how we shall execute the process from the client in the menuserver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MenuProcess.ex
Return the current menu state | ||
Add items to the menu | ||
Handle wrong entries | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention what start_link
does with regards to spawning processes and PIDs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @WanjikuMac good progress on your write up, I left a few thoughts to help with some parts ... excited to see this over the hill
@@ -1,4 +1,5 @@ | |||
**Maintain and update processes** | |||
|
|||
A few months ago, I walked into a restaurant with a friend to grab a meal. | |||
The first thing we needed was a menu(to enable us place our orders) which was supposed to be brought by the waiter, | |||
that process ended up taking over 30 min. As we were was waiting, I noticed some customers walk out without placing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WanjikuMac without placing what?
For the client requests to be handled on the server, start_link is called, the function menu_state is spawned to its own | ||
process then passed the initial state which in our case will change from an empty [] to an actual list of items to be | ||
added to the menu. The function responsible for that is shown below; | ||
start_link begins a spawn linked to the current process with the given functions, the pid is registered using `Process.register`. For the client requests to be handled on the server, start_link is called, the function menu_state is spawned to its own process then passed the initial state which in our case will change from an empty [] to an actual list of items to be added to the menu. The function responsible for that is shown below; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is a little ambiguous, it's hard to tell if this is true for all processes or just this one in particular
@spec start_link(any()) :: pid() | ||
def start_link(initial_state \\ []) do | ||
pid = spawn(__MODULE__, :menu_state, [initial_state]) | ||
Process.register(pid, :process) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using Process.register at this point of the reading is a red herring, I am not sure what purpose it serves
pid | ||
end | ||
end | ||
``` | ||
|
||
Return the current menu state: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What returns the current menu context, I would try and provide more context to keep the reader involved
send :process, {self(), :items} | ||
receive do state -> inspect state end | ||
end | ||
``` | ||
|
||
Adding a list of items to our menu list is handled by a different function which takes in {self(), :additems, items} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show each functionality individually and demostrate it here too to show the reader the complete story
|
||
**add iex code** | ||
Fire up iex and excute the following commands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would sprinkle this demos around the articles as their code comes up rather than bunch them all up at the end
#1