Use cancel_on_user_sig_term in main

to cancel the execution if users requested termination via signal.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-04 19:42:47 +10:00
parent 47ab8f55c7
commit b921e9dfc8
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -188,23 +188,20 @@ fn main() -> MainExit {
let start = Instant::now(); let start = Instant::now();
let rt = Runtime::new().unwrap(); let rt = Runtime::new().unwrap();
let handle = rt.spawn(entry(jobserver_client)); let handle = AutoAbortJoinHandle::new(rt.spawn(entry(jobserver_client)));
let result = rt.block_on(handle); let result = rt.block_on(cancel_on_user_sig_term(handle));
drop(rt); drop(rt);
let done = start.elapsed(); let done = start.elapsed();
debug!("run time: {done:?}"); debug!("run time: {done:?}");
result.map_or_else( result.map_or_else(MainExit::Error, |res| {
|join_err| MainExit::Error(BinstallError::from(join_err)), res.map(|()| MainExit::Success(done)).unwrap_or_else(|err| {
|res| { err.downcast::<BinstallError>()
res.map(|_| MainExit::Success(done)).unwrap_or_else(|err| { .map(MainExit::Error)
err.downcast::<BinstallError>() .unwrap_or_else(MainExit::Report)
.map(MainExit::Error) })
.unwrap_or_else(MainExit::Report) })
})
},
)
} }
async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {