Architecture For Referencing And Interacting Tasks Around
⚓ Rust 📅 2026-03-25 👤 surdeus 👁️ 4I’m posting here because we’ve been stuck on this for a long time. This is on behalf of McBrincie212—we couldn’t get any help on the Rust Discord, so I’m posting it here instead.
Summary
Currently im faced with a problem i've been battling for 2 weeks straight. In my system i have "Tasks" which contains their own TaskFrame, TaskTrigger and TaskHooks (a collection of them). Then i have "Schedulers" which are meant to own Tasks, the problem im faced goes as follows:
"How do I interact with the Task in outside code without holding anything related to the "Scheduler" everywhere, only the identification part of the Task."
For example, suppose a TaskDependency may want to inject its own TaskHooks, hence needs a way to communicate with the Task. Another example is suppose AlertTaskHook may want to fully remove a Task when it sees something... etc.
I have come up with two solutions:
-
Task / IDs Users assemble a
Task<T1, T2>struct whereT1andT2is the TaskFrame and TaskTrigger respectively. Then you can reference around via&Task<...>before being scheduled but when you need to schedule it on aScheduleryou need the owned part, then it returns an identifier helping you to reference it back via theScheduler(the identifier is clonable).- [✓] Simple to implement from my side (macros and
TaskFrameContext) - [✗] Two different APIs for the same thing
- [✗] During the identifier API, you must leak the Scheduler which owns this Task as well which is a bad pattern
- [✗] Assumes a specific storage shape mapping an ID to a Task (no flexibility)
- [✓] Simple to implement from my side (macros and
-
TaskHandles Its a similar idea to the above, but the difference is you explicitly tell the
Scheduler, theTaskFrameandTaskTriggerto allocate into a Task, then it returns a handle containing the location of the Task along with methods for interacting with it (including Scheduler-based operations).- [✓] Flexibility in how the storage layout is defined
- [✓] One unified API
- [✗] Difficulty in implementing the macros and
TaskFrameContext
The issue:
Before writing a full explanation about the problem and any clarifications. Do let me know first if anyone is willing to help out with the problem (as to not write an entire manifesto and waste time from ignorance). For the gh issue its not too suffecient to explain everything so if you have any questions, again let me know 100% predicting no one will be interested to help either from the get go or after the full explanation
2 posts - 2 participants
🏷️ Rust_feed
