Skip to content

Commit

Permalink
Move guard to element's GenServer
Browse files Browse the repository at this point in the history
  • Loading branch information
varsill committed Nov 27, 2023
1 parent 4968715 commit e12ea31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/membrane/core/element.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ defmodule Membrane.Core.Element do
end

defp do_handle_info(Message.new(:timer_tick, timer_id), state) do
state = %{state | supplying_demand?: true}
state = TimerController.handle_tick(timer_id, state)
state = %{state | supplying_demand?: false}
state = Membrane.Core.Element.DemandHandler.handle_delayed_demands(state)
{:noreply, state}
end

Expand Down
16 changes: 5 additions & 11 deletions lib/membrane/core/timer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ defmodule Membrane.Core.TimerController do

@spec handle_tick(Timer.id(), Component.state()) :: Component.state()
def handle_tick(timer_id, state) when is_timer_present(timer_id, state) do
state = %{state | supplying_demand?: true}

state =
CallbackHandler.exec_and_handle_callback(
:handle_tick,
Expand All @@ -70,15 +68,11 @@ defmodule Membrane.Core.TimerController do
)

# in case the timer was removed in handle_tick
state =
if is_timer_present(timer_id, state) do
update_in(state, [:synchronization, :timers, timer_id], &Timer.tick/1)
else
state
end

state = %{state | supplying_demand?: false}
Membrane.Core.Element.DemandHandler.handle_delayed_demands(state)
if is_timer_present(timer_id, state) do
update_in(state, [:synchronization, :timers, timer_id], &Timer.tick/1)
else
state
end
end

def handle_tick(_timer_id, state) do
Expand Down

0 comments on commit e12ea31

Please sign in to comment.