Skip to content

Commit e826741

Browse files
committed
fix split remaining
Signed-off-by: Teo Koon Peng <[email protected]>
1 parent c319992 commit e826741

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

diagram.schema.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,21 @@
205205
}
206206
},
207207
{
208-
"description": "Wait for an item to be emitted from each of the inputs, then combined the oldest of each into an array.\n\n# Examples ``` # bevy_impulse::Diagram::from_json_str(r#\" { \"version\": \"0.1.0\", \"start\": \"split\", \"ops\": { \"split\": { \"type\": \"split\", \"index\": [\"op1\", \"op2\"] }, \"op1\": { \"type\": \"node\", \"builder\": \"foo\", \"next\": \"join\" }, \"op2\": { \"type\": \"node\", \"builder\": \"bar\", \"next\": \"join\" }, \"join\": { \"type\": \"join\", \"order\": [\"op1\", \"op2\"], \"next\": { \"builtin\": \"terminate\" } } } } # \"#)?; # Ok::<_, serde_json::Error>(()) ```",
208+
"description": "Wait for an item to be emitted from each of the inputs, then combined the oldest of each into an array.\n\n# Examples ``` # bevy_impulse::Diagram::from_json_str(r#\" { \"version\": \"0.1.0\", \"start\": \"split\", \"ops\": { \"split\": { \"type\": \"split\", \"index\": [\"op1\", \"op2\"] }, \"op1\": { \"type\": \"node\", \"builder\": \"foo\", \"next\": \"join\" }, \"op2\": { \"type\": \"node\", \"builder\": \"bar\", \"next\": \"join\" }, \"join\": { \"type\": \"join\", \"inputs\": [\"op1\", \"op2\"], \"next\": { \"builtin\": \"terminate\" } } } } # \"#)?; # Ok::<_, serde_json::Error>(()) ```",
209209
"type": "object",
210210
"required": [
211+
"inputs",
211212
"next",
212-
"order",
213213
"type"
214214
],
215215
"properties": {
216+
"inputs": {
217+
"description": "Controls the order of the resulting join. Each item must be an operation id of one of the incoming outputs.",
218+
"type": "array",
219+
"items": {
220+
"$ref": "#/definitions/SourceOperation"
221+
}
222+
},
216223
"next": {
217224
"$ref": "#/definitions/NextOperation"
218225
},
@@ -223,13 +230,6 @@
223230
"null"
224231
]
225232
},
226-
"order": {
227-
"description": "Controls the order of the resulting join. Each item must be an operation id of one of the incoming outputs.",
228-
"type": "array",
229-
"items": {
230-
"$ref": "#/definitions/SourceOperation"
231-
}
232-
},
233233
"type": {
234234
"type": "string",
235235
"enum": [

src/diagram/workflow_builder.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,27 @@ fn connect_edge<'a>(
428428
let reg = registry.get_registration(&origin.builder)?;
429429
reg.split(builder, output, split_op)
430430
}?;
431-
for e in &target.out_edges {
431+
432+
// Because of how we build `out_edges`, if the split op uses the `remaining` slot,
433+
// then the last item will always be the remaining edge.
434+
let remaining_edge_id = if split_op.remaining.is_some() {
435+
Some(target.out_edges.last().unwrap())
436+
} else {
437+
None
438+
};
439+
let other_edge_ids = if split_op.remaining.is_some() {
440+
&target.out_edges[..(target.out_edges.len() - 1)]
441+
} else {
442+
&target.out_edges[..]
443+
};
444+
445+
for e in other_edge_ids {
432446
let out_edge = edges.get_mut(e).unwrap();
433447
let output = outputs.outputs.remove(out_edge.target).unwrap();
434448
out_edge.state = EdgeState::Ready { output, origin };
435449
}
436-
if let Some(_) = &split_op.remaining {
437-
let out_edge = edges.get_mut(target.out_edges.last().unwrap()).unwrap();
450+
if let Some(remaining_edge_id) = remaining_edge_id {
451+
let out_edge = edges.get_mut(remaining_edge_id).unwrap();
438452
out_edge.state = EdgeState::Ready {
439453
output: outputs.remaining,
440454
origin,

0 commit comments

Comments
 (0)