let step t: (bool, _) Deferred_result.t =
fold_active_targets t ~init:[] ~f:begin fun previous_happenings ~target ->
begin match Target.state target with
| s when Target.State.Is.finished s ->
move_target_to_finished_collection t ~target
>>= fun () ->
return []
| other ->
_process_automaton_transition t target
>>< function
| `Ok (new_target, progress) ->
add_or_update_targets t [new_target]
>>= fun () ->
Log.(s "Transition for target: "
% Target.log target
% s "Done: " % n
% Target.(State.log ~depth:2 (state new_target))
@ very_verbose);
return (progress :: previous_happenings)
| `Error `Empty_should_not_exist ->
return []
end
end
>>| List.exists ~f:((=) `Changed_state)
>>= fun has_progressed ->
Killing_targets.proceed_to_mass_killing t
>>= fun killing_did_something ->
Adding_targets.check_and_really_add_targets t
>>= fun adding_did_something ->
return (has_progressed || adding_did_something || killing_did_something)