Rust implementation of NextGraph, a Decentralized and local-first web 3.0 ecosystem
https://nextgraph.org
byzantine-fault-tolerancecrdtsdappsdecentralizede2eeeventual-consistencyjson-ldlocal-firstmarkdownocapoffline-firstp2pp2p-networkprivacy-protectionrdfrich-text-editorself-hostedsemantic-websparqlweb3collaboration
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
2 years ago
|
// All rights reserved.
|
||
|
// Licensed under the Apache License, Version 2.0
|
||
|
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
||
|
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||
|
// at your option. All files in the project carrying such
|
||
|
// notice may not be copied, modified, or distributed except
|
||
|
// according to those terms.
|
||
|
|
||
|
#[macro_export]
|
||
|
macro_rules! before {
|
||
|
( $self:expr, $request_id:ident, $addr:ident, $receiver:ident ) => {
|
||
|
let mut actor = BrokerMessageActor::new();
|
||
|
let $receiver = actor.receiver();
|
||
|
let mut $addr = actor
|
||
|
.start()
|
||
|
.await
|
||
|
.map_err(|_e| ProtocolError::ActorError)?;
|
||
|
|
||
|
let $request_id = $addr.actor_id();
|
||
|
//debug_println!("actor ID {}", $request_id);
|
||
|
|
||
|
{
|
||
|
let mut map = $self.actors.write().expect("RwLock poisoned");
|
||
|
map.insert($request_id, $addr.downgrade());
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
macro_rules! after {
|
||
|
( $self:expr, $request_id:ident, $addr:ident, $receiver:ident, $reply:ident ) => {
|
||
|
//debug_println!("waiting for reply");
|
||
|
|
||
|
$addr.wait_for_stop().await; // TODO add timeout and close connection if there's no reply
|
||
|
let r = $receiver.await;
|
||
|
if r.is_err() {
|
||
|
return Err(ProtocolError::Closing);
|
||
|
}
|
||
|
let $reply = r.unwrap();
|
||
|
//debug_println!("reply arrived {:?}", $reply);
|
||
|
{
|
||
|
let mut map = $self.actors.write().expect("RwLock poisoned");
|
||
|
map.remove(&$request_id);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#[cfg(not(target_arch = "wasm32"))]
|
||
|
pub mod remote_ws;
|
||
|
|
||
|
#[cfg(target_arch = "wasm32")]
|
||
|
pub mod remote_ws_wasm;
|