From 9fd203a01e0fe6fb307809fdfdbfcd3bda350cfc Mon Sep 17 00:00:00 2001 From: newpavlov Date: Fri, 30 Aug 2019 17:30:33 +0300 Subject: [PATCH] simplify code --- src/libstd/sys/wasi/thread.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/wasi/thread.rs b/src/libstd/sys/wasi/thread.rs index 987bf7580838b..28a504f197974 100644 --- a/src/libstd/sys/wasi/thread.rs +++ b/src/libstd/sys/wasi/thread.rs @@ -46,11 +46,18 @@ impl Thread { type_: wasi::EVENTTYPE_CLOCK, u: wasi::raw::__wasi_subscription_u { clock: clock }, }]; - let mut out: [wasi::Event; 1] = [unsafe { mem::zeroed() }]; - let n = unsafe { wasi::poll_oneoff(&in_, &mut out).unwrap() }; - let wasi::Event { userdata, error, type_, .. } = out[0]; - match (n, userdata, error) { - (1, CLOCK_ID, 0) if type_ == wasi::EVENTTYPE_CLOCK => {} + let (res, event) = unsafe { + let mut out: [wasi::Event; 1] = mem::zeroed(); + let res = wasi::poll_oneoff(&in_, &mut out); + (res, out[0]) + }; + match (res, event) { + (Ok(1), wasi::Event { + userdata: CLOCK_ID, + error: 0, + type_: wasi::EVENTTYPE_CLOCK, + .. + }) => {} _ => panic!("thread::sleep(): unexpected result of poll_oneoff"), } }