iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r806760492



##########
File path: src/smoosh/src/smoosh_channel.erl
##########
@@ -65,60 +77,80 @@ close(ServerRef) ->
 flush(ServerRef) ->
     gen_server:call(ServerRef, flush).
 
+is_key(ServerRef, Key) ->
+    gen_server:call(ServerRef, {is_key, Key}).
+
+is_activated(ServerRef) ->
+    gen_server:call(ServerRef, is_activated).
+
 % gen_server functions.
 
 init(Name) ->
     schedule_unpause(),
     erlang:send_after(60 * 1000, self(), check_window),
-    {ok, #state{name = Name}}.
+    process_flag(trap_exit, true),
+    Waiting = smoosh_priority_queue:new(Name),
+    State = #state{name = Name, waiting = Waiting, paused = true, activated = 
false},
+    ok = gen_server:cast(self(), init),
+    {ok, State}.
 
-handle_call({last_updated, Object}, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_call({last_updated, Object}, _From, State) ->
     LastUpdated = smoosh_priority_queue:last_updated(Object, 
State#state.waiting),
     {reply, LastUpdated, State};
-handle_call(suspend, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_call(suspend, _From, State) ->
     #state{active = Active} = State,
     [
         catch erlang:suspend_process(Pid, [unless_suspending])
      || {_, Pid} <- Active
     ],
     {reply, ok, State#state{paused = true}};
-handle_call(resume, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_call(resume, _From, State) ->
     #state{active = Active} = State,
     [catch erlang:resume_process(Pid) || {_, Pid} <- Active],
     {reply, ok, State#state{paused = false}};
-handle_call(status, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_call(status, _From, State) ->
     {reply,
         {ok, [
             {active, length(State#state.active)},
             {starting, length(State#state.starting)},
             {waiting, smoosh_priority_queue:info(State#state.waiting)}
         ]},
         State};
-handle_call(close, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_call(close, _From, State) ->
     {stop, normal, ok, State};
-handle_call(flush, _From, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
-    {reply, ok, State#state{waiting = smoosh_priority_queue:new()}}.
+handle_call(flush, _From, #state{waiting = Q} = State) ->
+    {reply, ok, State#state{waiting = smoosh_priority_queue:flush(Q)}};
+handle_call({is_key, Key}, _From, State) ->
+    #state{waiting = Waiting} = State,
+    {reply, smoosh_priority_queue:is_key(Key, Waiting), State};
+handle_call(is_activated, _From, #state{activated = Activated} = State0) ->
+    {reply, Activated, State0}.
 
-handle_cast({enqueue, _Object, 0}, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_cast(init, State0) ->
+    erlang:send_after(?START_DELAY_IN_MSEC, self(), start_recovery),
+    {noreply, State0};
+handle_cast({enqueue, _Object, 0}, #state{activated = true} = State) ->
     {noreply, State};
-handle_cast({enqueue, Object, Priority}, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
-    {noreply, maybe_start_compaction(add_to_queue(Object, Priority, State))}.
+handle_cast({enqueue, _Object, 0}, #state{activated = false} = State0) ->

Review comment:
       I don't see any difference in the body with a clause on line 132. I 
think we can combine the two.
   
   ```erlang
   handle_cast({enqueue, _Object, 0}, #state{} = State) ->
       {noreply, State};
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to