Skip to content

Commit

Permalink
[#976] Cancel requests asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoaloi committed Apr 9, 2021
1 parent 76fa5ff commit 3632fc6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions apps/els_core/src/els_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ handle_request(Provider, Request) ->

-spec cancel_request(provider(), pid()) -> any().
cancel_request(Provider, Job) ->
gen_server:call(Provider, {cancel_request, Job}).
gen_server:cast(Provider, {cancel_request, Job}).

%%==============================================================================
%% gen_server callbacks
Expand All @@ -90,22 +90,19 @@ init(Provider) ->
handle_call({handle_request, Request}, _From, State) ->
#{internal_state := InternalState, provider := Provider} = State,
{Reply, NewInternalState} = Provider:handle_request(Request, InternalState),
{reply, Reply, State#{internal_state => NewInternalState}};
handle_call({cancel_request, Job}, _From, State) ->
{reply, Reply, State#{internal_state => NewInternalState}}.

-spec handle_cast(any(), state()) -> {noreply, state()}.
handle_cast({cancel_request, Job}, State) ->
#{internal_state := InternalState, provider := Provider} = State,
case erlang:function_exported(Provider, cancel_request, 2) of
true ->
NewInternalState = Provider:cancel_request(Job, InternalState),
{reply, ok, State#{internal_state => NewInternalState}};
{noreply, State#{internal_state => NewInternalState}};
false ->
{reply, ok, State}
{noreply, State}
end.

-spec handle_cast(any(), state()) ->
{noreply, state()}.
handle_cast(_Request, State) ->
{noreply, State}.

-spec handle_info(any(), state()) ->
{noreply, state()}.
handle_info(Request, State) ->
Expand Down

0 comments on commit 3632fc6

Please sign in to comment.