Skip to content

Commit 3086581

Browse files
committed
Initial trait-based workflow API skeleton
1 parent a155eeb commit 3086581

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

workflow-api/src/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<T> TemporalDeserializable for T {}
8080
mod tests {
8181
use super::*;
8282
use futures::FutureExt;
83-
use std::collections::HashMap;
83+
use std::{collections::HashMap, marker::PhantomData};
8484

8585
// Workflow implementation example
8686
struct MyWorkflow {
@@ -112,6 +112,7 @@ mod tests {
112112
}
113113
}
114114

115+
// #[workflow] miiiight be necessary here, but, ideally is not.
115116
impl MyWorkflow {
116117
// Attrib commented out since nonexistent for now, but that's what it'd look like.
117118
// #[signal]
@@ -123,4 +124,37 @@ mod tests {
123124
self.bar.get(&arg).cloned()
124125
}
125126
}
127+
128+
// This would need to be moved into this crate and depended on by client
129+
struct WorkflowHandle<WF: Workflow> {
130+
_d: PhantomData<WF>,
131+
}
132+
struct SignalError; // just a placeholder
133+
struct QueryError; // just a placeholder
134+
135+
// The signal/query macros would generate this trait and impl:
136+
trait MyWorkflowClientExtension {
137+
fn my_signal(&self, arg: String) -> BoxFuture<Result<(), SignalError>>;
138+
fn my_query(&self, arg: String) -> BoxFuture<Result<Option<u64>, QueryError>>;
139+
}
140+
impl MyWorkflowClientExtension for WorkflowHandle<MyWorkflow> {
141+
fn my_signal(&self, arg: String) -> BoxFuture<Result<(), SignalError>> {
142+
// Is actually something like:
143+
// self.signal("my_signal", arg.serialize())
144+
todo!()
145+
}
146+
147+
fn my_query(&self, arg: String) -> BoxFuture<Result<Option<u64>, QueryError>> {
148+
todo!()
149+
}
150+
}
151+
152+
async fn client_example() {
153+
// Now you can use the client like:
154+
// (actually comes from client.start() or client.get_handle() etc)
155+
let wfh = WorkflowHandle {
156+
_d: PhantomData::<MyWorkflow>,
157+
};
158+
let _ = wfh.my_signal("hi!".to_string()).await;
159+
}
126160
}

0 commit comments

Comments
 (0)