123456789101112131415161718192021222324252627282930313233343536(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*)exceptionWorker_should_exitlet()=Callback.register_exception"worker_should_exit"Worker_should_exitexternalstop_workers:unit->unit="hh_stop_workers"externalresume_workers:unit->unit="hh_resume_workers"externalcheck_should_exit:unit->unit="hh_check_should_exit"externalset_can_worker_stop:bool->unit="hh_set_can_worker_stop"leton_worker_cancelled=ref(fun()->())letset_on_worker_cancelledf=on_worker_cancelled:=fletwith_no_cancellationsf=Utils.try_finally~f:beginfun()->set_can_worker_stopfalse;f()end~finally:(fun()->set_can_worker_stoptrue)letwith_worker_exitf=tryf()with|Worker_should_exit->!on_worker_cancelled();exit0(* Check if the workers are stopped and exit if they are *)letcheck_should_exit()=with_worker_exitcheck_should_exit