When to TagValue
While a TagValue makes good sense in client-server software, it must be stressed that it's equally helpful in other scenarios.
The Quartex Pascal RTL try to use TagValues whenever it deals with the DOM or Node.js, because the nature of asynchronous programming is that you have no guarantee that a call will return on time. It depends completely on the amount of activity.
Throughout the RTL you will find methods that follow this pattern:
type
// A defined callback procedure for re-entry, that delivers the TagValue back
// It also delivers any exception object that have occurred, so that the invoker can decide what to do
TCallBackType = procedure (TagValue: variant; .. Error: Exception);
// A procedure that takes TagValue as it's first parameter, and the callback type for re-entry
procedure TSomeClass.SomeMethod(TagValue: variant; CB: TCallBackType);
The rule of thumb is as follows:
- When writing API's that uses asynchronous objects, like sockets, the file-system, video encoding - anything that is non-blocking, always follow the above pattern
- If a procedure can fail, always export the exception back to the invoker (important!). Only raise exceptions if no callback handler is provided.