mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-01 20:07:39 +03:00
Feature/add spawn with (#516)
* Adds send bound to arbiter exec * Adds spawn with function --------- Co-authored-by: James Bell <jamesbell@microsoft.com>
This commit is contained in:
parent
9c78181c7b
commit
dcc08b72d8
2 changed files with 28 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
# Changes
|
||||
|
||||
## [0.4.26] - 2025-03-12
|
||||
## [0.4.27] - 2025-03-14
|
||||
|
||||
* Add Arbiter::spawn_with()
|
||||
|
||||
* Add "neon" runtime support
|
||||
|
||||
|
@ -8,6 +10,10 @@
|
|||
|
||||
* Drop async-std support
|
||||
|
||||
## [0.4.26] - 2025-03-12
|
||||
|
||||
* Add Arbiter::spawn_with()
|
||||
|
||||
## [0.4.25] - 2025-03-11
|
||||
|
||||
* Adds Send bound to arbiter exec (#514)
|
||||
|
|
|
@ -154,6 +154,27 @@ impl Arbiter {
|
|||
.try_send(ArbiterCommand::Execute(Box::pin(future)));
|
||||
}
|
||||
|
||||
/// Send a function to the Arbiter's thread and spawns it's resulting future.
|
||||
/// This can be used to spawn non-send futures on the arbiter thread.
|
||||
pub fn spawn_with<F, R, O>(&self, f: F) -> impl Future<Output = Result<O, oneshot::RecvError>> + Send + 'static
|
||||
where
|
||||
F: FnOnce() -> R + Send + 'static,
|
||||
R: Future<Output = O> + 'static,
|
||||
O: Send + 'static
|
||||
{
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self
|
||||
.sender
|
||||
.try_send(ArbiterCommand::ExecuteFn(Box::new(move || {
|
||||
let fut = f();
|
||||
let fut = Box::pin(async {
|
||||
let _ = tx.send(fut.await);
|
||||
});
|
||||
crate::spawn(fut);
|
||||
})));
|
||||
rx
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
/// Send a function to the Arbiter's thread. This function will be executed asynchronously.
|
||||
/// A future is created, and when resolved will contain the result of the function sent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue