You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passthough actions (AddSoftSelectedMember_PassthroughAction, RemoveViewport_PassthroughAction) are used as a way to run code as part of ActionAccumulator action processing pipeline. The pipeline generally operates in a 1. Pass accumulated actions to ChangeableDocument -> 2. Wait for them to be processed -> 3. Update UI stuff based on the results of processing cycle. Passthrough actions are "dummy" actions, they don't do anything in ChangeableDocument, and instead that pass straight though and trigger some code to be executed in DocumentUpdater. Since this happens in the stage 3 of the pipeline, there is a guarantee that no code is currently being executed in a separate thread in ChangeableDocument (it only happens during stage 2).
Right now passthough actions are inconvenient to use, as you have to create a whole new class, then add a condition to DocumentUpdater, and then somehow pass the "return" value to whereever you need it.
My initialy idea is to make a single generic passthough action that would contain a lambda to be executed. Something in DocumentUpdater would just call that lambda. This already solves the "create new class for each action" problem, but we can do even better.
The passthough action can also contain a promise. DocumentUpdater would be resolve that promise with the returned value of the lambda. A helper method that conveniently creates a new PassthoughAction from lambda and returns it's promise can be made. As a result, you'd be able to do something like:
...
var result =await ActionAccumulator.ExecuteInPipeline(a => ...);
...
This makes writing thread safe code very easy.
Now, I swear that 3 months ago when I came up with this idea I saw some giant caveat along the lines of "This is all very cool, but if you capture a wrong this into the lambda and do something with it, everything will break". However hard I try I can't remember what it was, nor can I come up with anything new that would break stuff. So everything's probably fine?
The text was updated successfully, but these errors were encountered:
Passthough actions (
AddSoftSelectedMember_PassthroughAction
,RemoveViewport_PassthroughAction
) are used as a way to run code as part of ActionAccumulator action processing pipeline. The pipeline generally operates in a1. Pass accumulated actions to ChangeableDocument
->2. Wait for them to be processed
->3. Update UI stuff based on the results of processing
cycle. Passthrough actions are "dummy" actions, they don't do anything inChangeableDocument
, and instead that pass straight though and trigger some code to be executed inDocumentUpdater
. Since this happens in the stage 3 of the pipeline, there is a guarantee that no code is currently being executed in a separate thread inChangeableDocument
(it only happens during stage 2).Right now passthough actions are inconvenient to use, as you have to create a whole new class, then add a condition to
DocumentUpdater
, and then somehow pass the "return" value to whereever you need it.My initialy idea is to make a single generic passthough action that would contain a lambda to be executed. Something in
DocumentUpdater
would just call that lambda. This already solves the "create new class for each action" problem, but we can do even better.The passthough action can also contain a promise.
DocumentUpdater
would be resolve that promise with the returned value of the lambda. A helper method that conveniently creates a newPassthoughAction
from lambda and returns it's promise can be made. As a result, you'd be able to do something like:This makes writing thread safe code very easy.
Now, I swear that 3 months ago when I came up with this idea I saw some giant caveat along the lines of "This is all very cool, but if you capture a wrong this into the lambda and do something with it, everything will break". However hard I try I can't remember what it was, nor can I come up with anything new that would break stuff. So everything's probably fine?
The text was updated successfully, but these errors were encountered: