mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
futures-ext: add ensure_boxfuture! macro similar to failure's ensure!
Summary: As in the comment to the macro: if the condition is not met, return a BoxFuture with Err inside Reviewed By: farnz Differential Revision: D8877731 fbshipit-source-id: 7f31a1739155201ea2be30901b8cda2511f49b03
This commit is contained in:
parent
836f34b6bd
commit
af3d993cd3
@ -485,6 +485,30 @@ macro_rules! try_boxstream {
|
||||
})
|
||||
}
|
||||
|
||||
/// Macro that can be used like ensure! macro from failure crate, but in the context where the
|
||||
/// expected return type is BoxFuture. Exits a function early with an Error if the condition is not
|
||||
/// satisfied.
|
||||
#[macro_export]
|
||||
macro_rules! ensure_boxfuture {
|
||||
($cond:expr, $e:expr) => {
|
||||
if !($cond) {
|
||||
return ::futures::future::err($e.into()).boxify();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Macro that can be used like ensure! macro from failure crate, but in the context where the
|
||||
/// expected return type is BoxStream. Exits a function early with an Error if the condition is not
|
||||
/// satisfied.
|
||||
#[macro_export]
|
||||
macro_rules! ensure_boxstream {
|
||||
($cond:expr, $e:expr) => {
|
||||
if !($cond) {
|
||||
return ::futures::stream::once(Err($e.into())).boxify();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// This method allows us to take synchronous code, schedule it on the default tokio thread pool
|
||||
/// and convert it to the future. Func can return anything that is convertable to a future, for
|
||||
/// example, Result
|
||||
|
Loading…
Reference in New Issue
Block a user