1pub mod codec;
2pub mod context;
3pub mod core;
4pub mod durable;
5pub mod effects;
6pub mod error;
7pub mod futures;
8pub mod handle;
9pub mod heartbeat;
10pub mod http_network;
11pub mod info;
12pub mod network;
13pub mod options;
14pub mod promises;
15pub mod registry;
16pub mod resonate;
17pub mod send;
18pub(crate) mod sequencing;
19pub mod transport;
20pub mod types;
21
22pub(crate) const PROTOCOL_VERSION: &str = "2026-04-01";
24
25use dashmap::DashMap;
30use std::any::{type_name, Any, TypeId};
31use std::sync::Arc;
32
33#[derive(Default)]
38pub(crate) struct DependencyMap {
39 map: DashMap<TypeId, Arc<dyn Any + Send + Sync>>,
40}
41
42impl std::fmt::Debug for DependencyMap {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 f.debug_struct("DependencyMap")
45 .field("len", &self.map.len())
46 .finish()
47 }
48}
49
50impl DependencyMap {
51 pub fn new() -> Self {
52 Self::default()
53 }
54
55 pub fn insert<T: Send + Sync + 'static>(&self, value: T) {
57 self.map.insert(TypeId::of::<T>(), Arc::new(value));
58 }
59
60 pub fn get<T: Send + Sync + 'static>(&self) -> Arc<T> {
62 self.map
63 .get(&TypeId::of::<T>())
64 .unwrap_or_else(|| {
65 panic!(
66 "Dependency `{}` not found. Did you forget to call `.with_dependency()`?",
67 type_name::<T>()
68 )
69 })
70 .clone()
71 .downcast::<T>()
72 .expect("dependency type mismatch (bug)")
73 }
74}
75
76pub(crate) fn now_ms() -> i64 {
78 std::time::SystemTime::now()
79 .duration_since(std::time::UNIX_EPOCH)
80 .unwrap()
81 .as_millis() as i64
82}
83
84#[cfg(test)]
85mod test_utils;
86
87pub use resonate_sdk_macros::function;
89
90pub mod prelude {
92 pub use crate::codec::Codec;
93 pub use crate::codec::{Encryptor, NoopEncryptor};
94 pub use crate::context::{Context, RpcTask, RunTask};
95 pub use crate::durable::{Durable, ExecutionEnv};
96 pub use crate::effects::Effects;
97 pub use crate::error::{Error, Result};
98 pub use crate::futures::{DetachedHandle, DurableFuture, RemoteFuture};
99 pub use crate::handle::ResonateHandle;
100 pub use crate::heartbeat::Heartbeat;
101 pub use crate::http_network::HttpNetwork;
102 pub use crate::info::Info;
103 pub use crate::network::Network;
104 pub use crate::options::Options;
105 pub use crate::promises::{Promises, Schedules};
106 pub use crate::registry::Registry;
107 pub use crate::resonate::{
108 ResRpcTask, ResRunTask, ResScheduleTask, Resonate, ResonateConfig, ResonateSchedule,
109 };
110 pub use crate::transport::Transport;
111 pub use crate::types::{DurableKind, Outcome, PromiseState};
112 pub use resonate_sdk_macros::function;
113}