-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
376 additions
and
504 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use yew::prelude::*; | ||
|
||
use super::provider::OneshotProviderState; | ||
use super::Oneshot; | ||
|
||
/// Handle for [use_bridge_oneshot] | ||
#[derive(Debug)] | ||
pub struct UseBridgeOneshotHandle<T> | ||
where | ||
T: Oneshot + 'static, | ||
{ | ||
state: OneshotProviderState<T>, | ||
} | ||
|
||
impl<T> UseBridgeOneshotHandle<T> | ||
where | ||
T: Oneshot + 'static, | ||
{ | ||
/// Runs an oneshot agent. | ||
pub async fn run(&self, input: T::Input) -> T::Output { | ||
self.state.create_bridge().run(input).await | ||
} | ||
} | ||
|
||
impl<T> Clone for UseBridgeOneshotHandle<T> | ||
where | ||
T: Oneshot + 'static, | ||
{ | ||
fn clone(&self) -> Self { | ||
Self { | ||
state: self.state.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> PartialEq for UseBridgeOneshotHandle<T> | ||
where | ||
T: Oneshot, | ||
{ | ||
fn eq(&self, rhs: &Self) -> bool { | ||
self.state == rhs.state | ||
} | ||
} | ||
|
||
/// A hook to bridge to an oneshot agent. | ||
#[hook] | ||
pub fn use_bridge_oneshot<T>() -> UseBridgeOneshotHandle<T> | ||
where | ||
T: Oneshot + 'static, | ||
{ | ||
let state = use_context::<OneshotProviderState<T>>().expect("failed to find worker context"); | ||
|
||
UseBridgeOneshotHandle { state } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! This module provides task agent implementation. | ||
mod hooks; | ||
mod provider; | ||
|
||
#[doc(inline)] | ||
pub use gloo_worker::oneshot::{Oneshot, OneshotBridge, OneshotRegistrar, OneshotSpawner}; | ||
pub use hooks::{use_bridge_oneshot, UseBridgeOneshotHandle}; | ||
pub use provider::OneshotProvider; | ||
pub(crate) use provider::OneshotProviderState; |
Oops, something went wrong.