linera_base/util/
future.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/*!
5Utilities for working with `Future`s.
6*/
7
8use std::{future::Future, pin::Pin};
9
10use sync_wrapper::SyncFuture;
11
12/// An extension trait to box futures and make them `Sync`.
13pub trait FutureSyncExt: Future + Sized {
14    /// Wrap the future so that it implements `Sync`
15    fn make_sync(self) -> SyncFuture<Self> {
16        SyncFuture::new(self)
17    }
18
19    /// Box the future without losing `Sync`ness
20    fn boxed_sync(self) -> Pin<Box<SyncFuture<Self>>> {
21        Box::pin(self.make_sync())
22    }
23}
24
25impl<F: Future> FutureSyncExt for F {}