Skip to content

Commit 8df1bfc

Browse files
committed
added examples
1 parent ff6e1b7 commit 8df1bfc

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

rfcs/side-effect-lifecycle-scheduling.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,44 @@ We can express this required ordering with labels, before, and after, but they l
2525
* Readers and writers must be after the producer and before the consumer. They can run in any order in relation to other readers and writers. If there needs to be an order between readers and writers, use the normal before and after labeling.
2626
* Consumers are run after producers, readers, and writers. There should only be one consumer of a type of side effect.
2727

28-
### Some Examples
28+
### Some Simple Examples
2929

30-
> TODO: add example of how api works with run criteria, commands, and maybe something else
30+
#### Scheduling around command application
31+
```rs
32+
fn main() {
33+
App::new()
34+
.add_system(apply_commands_buffer.consumes("commands"))
35+
// if we don't care about when the commands are applied
36+
// we can ignore the new api
37+
.add_system(create_commands_A)
38+
39+
// if we need to schedule a system after commands are applied
40+
.add_system(create_commands_A.label("system A").produces("commands"))
41+
.add_system(after_commands_A.after("system A").after("commands"))
42+
}
43+
```
44+
45+
#### Systems dependent on app state
46+
```rs
47+
// this is not an example of how a final api for app state
48+
// or run criteria is expected to look. Just a way to highlight
49+
// the relations between the systems that produce those side effects
50+
51+
fn main() {
52+
App::new()
53+
.add_system(system_that_queues_state_change.produces("state change"))
54+
.add_system(system_that_applies_state_queue
55+
.consumes("state change")
56+
.produces("state")
57+
)
58+
.add_system(run_criteria
59+
.reads("state")
60+
.produces("on update state=A")
61+
)
62+
.add_system(system_A.reads("on update state=A"))
63+
.add_system(system_B.reads("on update state=A"))
64+
}
65+
```
3166

3267
## Implementation
3368

@@ -71,16 +106,16 @@ In practice we can't create these system sets like this as it would be very uner
71106
72107
## Drawbacks
73108

74-
* as this builds on the existing labeling system, there shouldn't be much in terms of performance issues
75-
76-
## Alternatives Considered
77-
78-
* The example above for expressing the relationships between side effects using just labeling and system sets has one major problem. There is no current api for adding systems to system sets after the system set has been created. If such an api did exist we could potentially just add systems to the correct system set. This didn't seem better than the proposed API and has some implementation complexity since system sets are mostly just api sugar for labeling multiple systems and does not exist at runtime.
109+
I expect that these relationships will mostly be added automatically when using run criteria, app state, and the like. Users would only be expected to interact with this API when things can't be done automatically or the default behavior doesn't match their needs.
79110

80111
## Open questions
81112

82113
* With looping criteria it might be possible to create a valid dependency cycle that cannot be resolved in the current API. If that is the case then we might need an `.after_can_break` type of edge that could be ignored in dependency cycle checking.
83114

115+
## Alternatives Considered
116+
117+
* The example above for expressing the relationships between side effects using just labeling and system sets has one major problem. There is no current api for adding systems to system sets after the system set has been created. If such an api did exist we could potentially just add systems to the correct system set. This didn't seem better than the proposed API and has some implementation complexity since system sets are mostly just api sugar for labeling multiple systems and does not exist at runtime.
118+
84119
## Future Work
85120

86121
* This is part of a bigger redesign of the ECS trying to solve problems with scheduling around hard sync points and data consistency between states. This RFC by itself doesn't solve those problems, but it does encode information about dependencies that other RFCs might need to actually solve the data consistency problems.

0 commit comments

Comments
 (0)