Skip to content
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

Create Agent for timer state #5

Merged
merged 7 commits into from
Jun 18, 2022
Merged

Create Agent for timer state #5

merged 7 commits into from
Jun 18, 2022

Conversation

SimonLab
Copy link
Member

Use agent to manage the state of the Timer

Use agent to manage the state of the Timer
@SimonLab SimonLab added the in-progress An issue or pull request that is being worked on by the assigned person label Jun 17, 2022
@SimonLab SimonLab self-assigned this Jun 17, 2022
@@ -13,9 +13,10 @@ defmodule Stopwatch.Application do
# Start the PubSub system
{Phoenix.PubSub, name: Stopwatch.PubSub},
# Start the Endpoint (http/https)
StopwatchWeb.Endpoint
StopwatchWeb.Endpoint,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application will create the timer by calling Stopwatch.Timer.start_link\1 function

use Agent

def start_link(_opts) do
Agent.start_link(fn -> ~T[00:00:00] end, name: __MODULE__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name are atoms so we can use it as the name for the timer agent

Using PubSub to have multiple clients
listening to the stopwatch
Create test for agent
@SimonLab
Copy link
Member Author

The stopwatch state is now shared between client using Agent. This can be tested at https://liveview-stopwatch.fly.dev/
I'm going to update the Readme to explain how it's done

Add Agent section in Readme
@SimonLab SimonLab marked this pull request as ready for review June 17, 2022 14:55
@SimonLab SimonLab requested a review from nelsonic June 17, 2022 14:55
@SimonLab SimonLab assigned nelsonic and unassigned SimonLab Jun 17, 2022
@SimonLab SimonLab added awaiting-review An issue or pull request that needs to be reviewed and removed in-progress An issue or pull request that is being worked on by the assigned person labels Jun 17, 2022
@SimonLab
Copy link
Member Author

@nelsonic let me know if all this makes sense, thanks

@nelsonic nelsonic added in-review Issue or pull request that is currently being reviewed by the assigned person priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished and removed awaiting-review An issue or pull request that needs to be reviewed labels Jun 17, 2022
SimonLab and others added 3 commits June 17, 2022 22:38
Create a reset function in the Timer agent.
Update the html to display the reset button
and handle the "reset" event with liveview
Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonLab superb addition! 🎉

liveview-stopwatch-sync

Thanks! ⭐

@nelsonic nelsonic merged commit 3dd0b16 into main Jun 18, 2022
@nelsonic nelsonic deleted the timer-agent branch June 18, 2022 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-review Issue or pull request that is currently being reviewed by the assigned person priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants