Handling expired solutions on downstream components

Suppose I have a number of components connected in sequence, say A→B→C or A→C & B→C and I have a global event handler that fires on change of model units in Rhino. These components’ output depends on the currently selected model units, so with every change I want them to update their outputs (solve).

If I have all 3 components registered to this event handler and call ExpireSolution(true) in the order they appear (first A, then B, then C), I will get into the following nasty situation:

  1. Component A solves, leading to B solving and C afterwards.
  2. Component B solves, leading to C solving as well.
  3. Component C solves.

Therefore, component B will be solved twice and C thrice. It happens that component C runs external tools which may take minutes to complete, therefore this situation is unacceptable for my plugin.

I have thought of some possible solutions but I am unaware of their feasibility in Grasshopper:

  • Use ScheduleSolution. However, this seems to shedule the solution of an entire GH_Document and not specific components.
  • Expire the solution of A,B,C and at the end, run a solution for these components which will only run once.
  • Use local variables to store the last solved units on each component and decide whether to continue in SolveInstance. This could prevent component C running a second time if it already ran after step 1. above. However, at step 2. solution of component B will trigger SolveInstance for component C, and even if I return early, the outputs will have been wiped out already.

This is a lot of information, so I could clarify if anyone thinks he can help.

You might find these helpful

Thanks for the links. While reading, I realised I was wrong in my OP about ScheduleSolution.

It seems I can expire all components (A,B,C as in the OP) with ExpireSolution(false) and then use ScheduleSolution(1) to make the document run all expired objects, which will lead to a single solution.

If there isn’t any caveat to the above process that I cannot think of, this could be a solution.