Skip to content

Commit

Permalink
Remove some calls to Bunch.Access
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Jul 12, 2023
1 parent f148124 commit ccb91e9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/membrane/clock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ defmodule Membrane.Clock do

defp handle_unsubscribe(pid, state) do
Process.demonitor(state.subscribers[pid].monitor, [:flush])
state |> Bunch.Access.delete_in([:subscribers, pid])
{_subscriber, state} = pop_in(state, [:subscribers, pid])
state
end

defp handle_clock_update({nom, denom}, state) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
) :: Pipeline.State.t()
def add_crash_group(group_name, _mode, children, state)
when is_map_key(state.crash_group, group_name) do
Bunch.Access.update_in(state, [:crash_groups, group_name, :members], &(children ++ &1))
update_in(state, [:crash_groups, group_name, :members], &(children ++ &1))
end

def add_crash_group(group_name, mode, children, state) do
Bunch.Access.put_in(
put_in(
state,
[:crash_groups, group_name],
%CrashGroup{
Expand Down Expand Up @@ -58,7 +58,8 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
:normal,
state
) do
Bunch.Access.delete_in(state, [:crash_groups, group.name])
{_group, state} = pop_in(state, [:crash_groups, group.name])
state
end

def handle_crash_group_member_death(
Expand All @@ -73,7 +74,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
end

def handle_crash_group_member_death(child_name, %CrashGroup{} = group, :normal, state) do
Bunch.Access.update_in(
update_in(
state,
[:crash_groups, group.name, :members],
&List.delete(&1, child_name)
Expand All @@ -90,7 +91,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
|> Process.exit({:shutdown, :membrane_crash_group_kill})
end)

Bunch.Access.put_in(state, [:crash_groups, group.name], %CrashGroup{
put_in(state, [:crash_groups, group.name], %CrashGroup{
group
| triggered?: true,
crash_initiator: child_name
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane/core/timer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ defmodule Membrane.Core.TimerController do
stop_and_unsubscribe(timer)
end

Bunch.Access.put_in(state, [:synchronization, :timers], %{})
put_in(state, [:synchronization, :timers], %{})
end

@spec stop_timer(Timer.id(), Component.state()) :: Component.state()
def stop_timer(id, state) do
{timer, state} = state |> Bunch.Access.pop_in([:synchronization, :timers, id])
{timer, state} = state |> pop_in([:synchronization, :timers, id])

if timer |> is_nil do
raise Membrane.TimerError, "Timer #{inspect(id)} doesn't exist"
Expand Down
6 changes: 5 additions & 1 deletion lib/membrane/sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ defmodule Membrane.Sync do

@impl true
def handle_info({:DOWN, _ref, :process, pid, _reason}, state) do
state = state |> Bunch.Access.delete_in([:processes, pid]) |> check_and_handle_sync()
state =
state
|> pop_in([:processes, pid])
|> elem(1)
|> check_and_handle_sync()

if state.empty_exit? and state.processes |> Enum.empty?() do
{:stop, :normal, state}
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/core/element/event_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule Membrane.Core.Element.EventControllerTest do
end

defp put_start_of_stream(state, pad_ref) do
Bunch.Access.update_in(state, [:pads_data, pad_ref], fn data ->
update_in(state, [:pads_data, pad_ref], fn data ->
%{data | start_of_stream?: true}
end)
end
Expand Down
6 changes: 3 additions & 3 deletions test/membrane/core/element/pad_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule Membrane.Core.Element.PadControllerTest do
{info, state} =
elem_module
|> prepare_state(name)
|> Bunch.Access.pop_in([:pads_info, pad_name])
|> pop_in([:pads_info, pad_name])

data =
struct(Membrane.Element.PadData,
Expand All @@ -89,7 +89,7 @@ defmodule Membrane.Core.Element.PadControllerTest do
|> Map.merge(info)

state
|> Bunch.Access.put_in([:pads_data, pad_name], data)
|> put_in([:pads_data, pad_name], data)
end

defp prepare_dynamic_state(elem_module, name, pad_name, pad_ref) do
Expand All @@ -103,7 +103,7 @@ defmodule Membrane.Core.Element.PadControllerTest do
)
|> Map.merge(info)

state |> Bunch.Access.put_in([:pads_data, pad_ref], data)
state |> put_in([:pads_data, pad_ref], data)
end

describe "handle_unlink" do
Expand Down

0 comments on commit ccb91e9

Please sign in to comment.