forked from holochain/holochain-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request holochain#1640 from holochain/feature-add-header-p…
…ublishing Header Publishing (The Return Of)
- Loading branch information
Showing
23 changed files
with
566 additions
and
94 deletions.
There are no files selected for viewing
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 crate::{ | ||
action::{Action, ActionWrapper}, | ||
context::Context, | ||
instance::dispatch_action, | ||
network::actions::ActionResponse, | ||
}; | ||
use futures::{future::Future, task::Poll}; | ||
use holochain_core_types::error::HcResult; | ||
use holochain_persistence_api::cas::content::Address; | ||
use std::{pin::Pin, sync::Arc}; | ||
|
||
/// Publish Header Entry Action Creator | ||
/// Returns a future that resolves to an ActionResponse. | ||
pub async fn publish_header_entry(address: Address, context: &Arc<Context>) -> HcResult<Address> { | ||
let action_wrapper = ActionWrapper::new(Action::PublishHeaderEntry(address)); | ||
dispatch_action(context.action_channel(), action_wrapper.clone()); | ||
await!(PublishHeaderEntryFuture { | ||
context: context.clone(), | ||
action: action_wrapper, | ||
}) | ||
} | ||
|
||
/// PublishFuture resolves to ActionResponse | ||
/// Tracks the state for a response to its ActionWrapper | ||
pub struct PublishHeaderEntryFuture { | ||
context: Arc<Context>, | ||
action: ActionWrapper, | ||
} | ||
|
||
impl Future for PublishHeaderEntryFuture { | ||
type Output = HcResult<Address>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context) -> Poll<Self::Output> { | ||
if let Some(err) = self.context.action_channel_error("PublishHeaderEntryFuture") { | ||
return Poll::Ready(Err(err)); | ||
} | ||
let state = self.context.state().unwrap().network(); | ||
if let Err(error) = state.initialized() { | ||
return Poll::Ready(Err(error)); | ||
} | ||
// | ||
// TODO: connect the waker to state updates for performance reasons | ||
// See: https://github.com/holochain/holochain-rust/issues/314 | ||
// | ||
cx.waker().clone().wake(); | ||
match state.actions().get(&self.action) { | ||
Some(ActionResponse::PublishHeaderEntry(result)) => match result { | ||
Ok(address) => Poll::Ready(Ok(address.to_owned())), | ||
Err(error) => Poll::Ready(Err(error.clone())), | ||
}, | ||
_ => Poll::Pending, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.