Skip to content

Commit 0f75ada

Browse files
committed
refactor: Switch parallel handles to a HashSet
1 parent 410d747 commit 0f75ada

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

obelisk.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ activities.directories.enabled = true # Allow file I/O for activities with `di
44

55
[log.stdout]
66
enabled = true
7-
level = "warn,obelisk=info,app=debug" # app=trace to see replays
7+
level = "warn,obelisk=info,app=trace" # app=trace to see replays
88

99
[[activity_wasm]]
1010
name = "activity_sleepy"

workflow-tutorial/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ use obelisk::{
44
types::time::{Duration, ScheduleAt},
55
workflow::workflow_support::{self, ClosingStrategy, new_join_set_generated},
66
};
7+
use std::collections::HashSet;
78
use tutorial::{
89
activity::activity_sleepy::step,
910
activity_obelisk_ext::activity_sleepy::{step_await_next, step_submit},
1011
};
1112
use wit_bindgen::generate;
1213

14+
mod util;
15+
1316
generate!({ generate_all });
1417
struct Component;
1518
export!(Component);
@@ -30,14 +33,15 @@ impl Guest for Component {
3033
Ok(acc)
3134
}
3235

36+
#[allow(clippy::mutable_key_type)]
3337
fn parallel() -> Result<u64, ()> {
3438
log::info("parallel started");
3539
let max_iterations = 10;
36-
let mut handles = Vec::new();
40+
let mut handles = HashSet::new();
3741
for i in 0..max_iterations {
3842
let join_set = new_join_set_generated(ClosingStrategy::Complete);
3943
step_submit(&join_set, i, i * 200);
40-
handles.push((i, join_set));
44+
handles.insert((i, join_set));
4145
}
4246
log::info("parallel submitted all child executions");
4347
let mut acc = 0;

workflow-tutorial/src/util.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// TODO: this should be generated or moved to SDK
2+
use crate::obelisk::types::execution::JoinSet;
3+
use std::hash::Hash;
4+
5+
impl PartialEq for JoinSet {
6+
fn eq(&self, other: &Self) -> bool {
7+
self.id() == other.id()
8+
}
9+
}
10+
impl Eq for JoinSet {}
11+
12+
impl Hash for JoinSet {
13+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
14+
self.id().hash(state);
15+
}
16+
}

0 commit comments

Comments
 (0)