Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

core: Rewrite await!(future) to future.await #1726

Merged
merged 6 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conductor_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Arc::new(Mutex::new(SimplePersister::new(file_system.clone()))),
//! file_system.clone(),

#![feature(try_trait, async_await, await_macro)]
#![feature(try_trait, async_await)]
#![warn(unused_extern_crates)]
/// Holochain Conductor API
///
Expand Down
1 change: 0 additions & 1 deletion core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,4 @@ pub mod tests {

assert_ne!(calculate_hash(&aw1), calculate_hash(&aw2));
}

}
5 changes: 3 additions & 2 deletions core/src/agent/actions/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub async fn commit_entry(
vec![],
)));
dispatch_action(context.action_channel(), action_wrapper.clone());
await!(CommitFuture {
CommitFuture {
context: context.clone(),
action: action_wrapper,
})
}
.await
}

/// CommitFuture resolves to ActionResponse
Expand Down
1 change: 0 additions & 1 deletion core/src/agent/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,5 +875,4 @@ pub mod tests {
assert_eq!(set.matches("src/bar/baz/foo.rs"), vec![2, 3]); // *.rs no longer matches, due to '/' separators
assert_eq!(set.matches("foo.rs"), vec![0, 3]); // but, any number of leading '/' are matched by a '**/...'
}

}
2 changes: 1 addition & 1 deletion core/src/dht/actions/hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn hold_entry(
let address = entry_wh.entry.address();
let action_wrapper = ActionWrapper::new(Action::Hold(entry_wh.to_owned()));
dispatch_action(context.action_channel(), action_wrapper.clone());
await!(HoldEntryFuture { context, address })
HoldEntryFuture { context, address }.await
}

pub struct HoldEntryFuture {
Expand Down
1 change: 0 additions & 1 deletion core/src/dht/dht_reducers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,4 @@ pub mod tests {

assert_eq!(&entry, &result_entry,);
}

}
18 changes: 7 additions & 11 deletions core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,10 @@ impl Instance {
context: Arc<Context>,
) -> HcResult<Arc<Context>> {
let context = self.inner_setup(context);
context.block_on(
async {
await!(initialize_chain(dna.clone(), &context))?;
await!(initialize_network_with_spoofed_dna(
spoofed_dna_address,
&context
))
},
)?;
context.block_on(async {
initialize_chain(dna.clone(), &context).await?;
initialize_network_with_spoofed_dna(spoofed_dna_address, &context).await
})?;
Ok(context)
}

Expand Down Expand Up @@ -339,10 +334,11 @@ impl Instance {

#[allow(clippy::needless_lifetimes)]
pub async fn shutdown_network(&self) -> HcResult<()> {
await!(network::actions::shutdown::shutdown(
network::actions::shutdown::shutdown(
self.state.clone(),
self.action_channel.as_ref().unwrap().clone(),
))
)
.await
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The library implementing the holochain pattern of validation rules + local source chain + DHT
#![feature(arbitrary_self_types, async_await, await_macro)]
#![feature(arbitrary_self_types, async_await)]
#![warn(unused_extern_crates)]
#[macro_use]
extern crate serde_derive;
Expand Down
1 change: 0 additions & 1 deletion core/src/link_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ pub mod tests {
_ => false,
});
}

}
5 changes: 3 additions & 2 deletions core/src/network/actions/custom_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ pub async fn custom_send(
})
.expect("Could not spawn thread for custom_send timeout");

await!(SendResponseFuture {
SendResponseFuture {
context: context.clone(),
id,
})
}
.await
}

/// SendResponseFuture waits for a result to show up in NetworkState::custom_direct_message_replys
Expand Down
5 changes: 3 additions & 2 deletions core/src/network/actions/get_validation_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ pub async fn get_validation_package(
let entry_address = header.entry_address().clone();
let action_wrapper = ActionWrapper::new(Action::GetValidationPackage(header));
dispatch_action(context.action_channel(), action_wrapper.clone());
await!(GetValidationPackageFuture {
GetValidationPackageFuture {
context: context.clone(),
address: entry_address,
})
}
.await
}

/// GetValidationPackageFuture resolves to an Option<ValidationPackage>
Expand Down
14 changes: 8 additions & 6 deletions core/src/network/actions/initialize_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{pin::Pin, sync::Arc};

/// Creates a network proxy object and stores DNA and agent hash in the network state.
pub async fn initialize_network(context: &Arc<Context>) -> HcResult<()> {
let (dna_address, agent_id) = await!(get_dna_and_agent(context))?;
let (dna_address, agent_id) = get_dna_and_agent(context).await?;
let handler = create_handler(&context, dna_address.to_string());
let network_settings = NetworkSettings {
p2p_config: context.p2p_config.clone(),
Expand All @@ -23,9 +23,10 @@ pub async fn initialize_network(context: &Arc<Context>) -> HcResult<()> {
let action_wrapper = ActionWrapper::new(Action::InitNetwork(network_settings));
dispatch_action(context.action_channel(), action_wrapper.clone());

await!(InitNetworkFuture {
InitNetworkFuture {
context: context.clone(),
})?;
}
.await?;

Ok(())
}
Expand All @@ -35,7 +36,7 @@ pub async fn initialize_network_with_spoofed_dna(
dna_address: Address,
context: &Arc<Context>,
) -> HcResult<()> {
let (_, agent_id) = await!(get_dna_and_agent(context))?;
let (_, agent_id) = get_dna_and_agent(context).await?;
let handler = create_handler(&context, dna_address.to_string());
let network_settings = NetworkSettings {
p2p_config: context.p2p_config.clone(),
Expand All @@ -46,9 +47,10 @@ pub async fn initialize_network_with_spoofed_dna(
let action_wrapper = ActionWrapper::new(Action::InitNetwork(network_settings));
dispatch_action(context.action_channel(), action_wrapper.clone());

await!(InitNetworkFuture {
InitNetworkFuture {
context: context.clone(),
})
}
.await
}

pub struct InitNetworkFuture {
Expand Down
5 changes: 3 additions & 2 deletions core/src/network/actions/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use std::{pin::Pin, sync::Arc};
pub async fn publish(address: Address, context: &Arc<Context>) -> HcResult<Address> {
let action_wrapper = ActionWrapper::new(Action::Publish(address));
dispatch_action(context.action_channel(), action_wrapper.clone());
await!(PublishFuture {
PublishFuture {
context: context.clone(),
action: action_wrapper,
})
}
.await
}

/// PublishFuture resolves to ActionResponse
Expand Down
5 changes: 3 additions & 2 deletions core/src/network/actions/publish_header_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use std::{pin::Pin, sync::Arc};
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 {
PublishHeaderEntryFuture {
context: context.clone(),
action: action_wrapper,
})
}
.await
}

/// PublishFuture resolves to ActionResponse
Expand Down
5 changes: 3 additions & 2 deletions core/src/network/actions/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ pub async fn query(
})
.expect("Could not spawn thread for get timeout");

await!(QueryFuture {
QueryFuture {
context: context.clone(),
key: key.clone(),
})
}
.await
}

/// GetEntryFuture resolves to a HcResult<Entry>.
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/actions/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn shutdown(
if state.read().unwrap().network().initialized().is_ok() {
let action_wrapper = ActionWrapper::new(Action::ShutdownNetwork);
dispatch_action(&action_channel, action_wrapper.clone());
await!(ShutdownFuture { state })
ShutdownFuture { state }.await
} else {
Err(HolochainError::ErrorGeneric(
"Tried to shutdown network that was never initialized".to_string(),
Expand Down
1 change: 0 additions & 1 deletion core/src/network/handler/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,4 @@ pub mod tests {
get_all_aspect_addresses(&chain_header.address(), context.clone()).is_ok()
}));
}

}
1 change: 0 additions & 1 deletion core/src/network/reducers/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ pub mod test {

assert_eq!(result, ());
}

}
1 change: 0 additions & 1 deletion core/src/network/reducers/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,4 @@ mod tests {

store.reduce(action_wrapper);
}

}
1 change: 0 additions & 1 deletion core/src/network/reducers/publish_header_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ mod tests {

store.reduce(action_wrapper);
}

}
5 changes: 3 additions & 2 deletions core/src/nucleus/actions/build_validation_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ pub async fn build_validation_package<'a>(
.expect("Could not spawn thread for build_validation_package");
}

await!(ValidationPackageFuture {
ValidationPackageFuture {
context: context.clone(),
key: id,
error: None,
})
}
.await
}

// given a slice of headers return the entries for those marked public
Expand Down
5 changes: 3 additions & 2 deletions core/src/nucleus/actions/call_zome_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ pub async fn call_zome_function(
zome_call
);

await!(CallResultFuture {
CallResultFuture {
context: context.clone(),
zome_call,
})
}
.await
}

/// validates that a given zome function call specifies a correct zome function and capability grant
Expand Down
16 changes: 7 additions & 9 deletions core/src/nucleus/actions/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn initialize_chain(

// Commit DNA to chain
let dna_entry = Entry::Dna(Box::new(dna.clone()));
let dna_commit = await!(commit_entry(dna_entry, None, &context_clone));
let dna_commit = commit_entry(dna_entry, None, &context_clone).await;
if dna_commit.is_err() {
let error = dna_commit.err().unwrap();
dispatch_error_result(&context_clone, error.clone());
Expand All @@ -91,7 +91,7 @@ pub async fn initialize_chain(

// Commit AgentId to chain
let agent_id_entry = Entry::AgentId(context_clone.agent_id.clone());
let agent_id_commit = await!(commit_entry(agent_id_entry, None, &context_clone));
let agent_id_commit = commit_entry(agent_id_entry, None, &context_clone).await;

// Let initialization fail if AgentId could not be committed.
// Currently this cannot happen since ToEntry for Agent always creates
Expand Down Expand Up @@ -139,11 +139,8 @@ pub async fn initialize_chain(
}

let grant = maybe_public_cap_grant_entry.ok().unwrap();
let public_cap_grant_commit = await!(commit_entry(
Entry::CapTokenGrant(grant.clone()),
None,
&context_clone
));
let public_cap_grant_commit =
commit_entry(Entry::CapTokenGrant(grant.clone()), None, &context_clone).await;

// Let initialization fail if Public Grant could not be committed.
match public_cap_grant_commit {
Expand Down Expand Up @@ -178,10 +175,11 @@ pub async fn initialize_chain(
)))
.expect("Action channel not usable in initialize_chain()");

await!(InitializationFuture {
InitializationFuture {
context: context.clone(),
created_at: Instant::now(),
})
}
.await
}

/// InitializationFuture resolves to an Ok(NucleusStatus) or an Err(String).
Expand Down
1 change: 0 additions & 1 deletion core/src/nucleus/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,4 @@ pub mod tests {
let (instance, _context) = instance(None);
assert!(instance.state().nucleus().has_initialized());
}

}
5 changes: 3 additions & 2 deletions core/src/nucleus/actions/run_validation_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ pub async fn run_validation_callback(
})
.expect("Could not spawn thread for validation callback");

await!(ValidationCallbackFuture {
ValidationCallbackFuture {
context: context.clone(),
key: (id, address),
})
}
.await
}

/// ValidationFuture resolves to an Ok(ActionWrapper) or an Err(error_message:String).
Expand Down
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,4 @@ pub mod tests {
);
assert!(check_capability(context.clone(), &zome_call));
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,4 @@ pub mod tests {
),
);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,4 @@ pub mod tests {
),
);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ mod test_super {
call_result,
);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/get_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,4 @@ pub mod tests {
// call_result,
// );
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/link_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,4 @@ pub mod tests {

assert_ne!(result1, result2);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/api/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ mod test_super {
call_result,
);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/callback/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ pub mod tests {
error
);
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/ribosome/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,4 @@ pub mod tests {
assert_eq!(output, Callback::from_index(input));
}
}

}
1 change: 0 additions & 1 deletion core/src/nucleus/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,4 @@ pub mod tests {
pub fn test_nucleus_state() -> NucleusState {
NucleusState::new()
}

}
Loading