Skip to content

Commit

Permalink
[doc] make async timings very specific (#1753)
Browse files Browse the repository at this point in the history
  • Loading branch information
MFransen69 authored Sep 18, 2024
1 parent 761d6d6 commit f14f96f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/plugin/interfaces/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Design interfaces to be asynchronous when needed {#AsynchronousInterfaces}
Sometimes when designing an interface it can be expected that the implementation of a certain action can be quite expensive and take some time.
In such a case (we usually use an expected duration of a few hundred milliseconds as the limit) or when the duration of an action is non deterministic and worse case would take longer than a few hundred milliseconds, it is advised to make the interface asynchronous. The interface will then only pass the data needed to start the action to the component and add a callback to the interface to make it possible for the implementation to return the result asynchronously. The component will handle the action in the background (do not use threads for this but use the Thunder workerpool) and call the provided callback when the action is completed to signal this to the initiator of the action. Not only will this prevent the call to fail because of JSON-RPC or COM-RPC timeouts but it will also make sure the framework is not blocked internally and also the client can continue without being blocked waiting for the result (or needed to reserve a thread for this).
As a rule anytime the execution of the call will take more than 100 milliseconds or when the duration of an action is non deterministic and worse case would take longer than 100 milliseconds, the interface must be made asynchronous. The interface will then only pass the data needed to start the action to the component and add a callback to the interface to make it possible for the implementation to return the result asynchronously. The component will handle the action in the background (do not use threads for this but use the Thunder workerpool) and call the provided callback when the action is completed to signal this to the initiator of the action. Not only will this prevent the call to fail because of JSON-RPC or COM-RPC timeouts but it will also make sure the framework is not blocked internally and also the client can continue without being blocked waiting for the result (or needed to reserve a thread for this).
For example an interface that will require user interaction for its action (like asking for the pin to be entered) is a perfect example of one that should be made asynchronous as it is of course completely nondeterministic when the call will return as the successful entering of the PIN could take minutes/hours potentially.
![Sequence Diagram showing Async example for getting a user PIN](../../assets/AsyncInterfaceExample.png)
Expand Down

0 comments on commit f14f96f

Please sign in to comment.