Are messages synchronous or asynchonous? What about actions in response to messages?

I’m curious to know something… if the first of two actions is action-sendmessage, is it possible for the second action to start before the message sent by the first action is completed?

For example, let’s say we have a <$linkcatcher> widget that stores the “navigateTo” in a tiddler $:/state/my/target, but only if it meets some condition.

<$action-sendmessage $message="tm-navigate" navigateTo=<<target>> />
<$action-setfield $field="success" $value={{{ [{$:/state/my/target}match<target>then[yes]else[no]] }}} />

Note that the second action essentially sets the field “success” to “yes” if the tiddler $:/state/my/target successfully gets the value of <<target>> stored in it from the first action. It is intended to determine the linkcatcher’s decision on whether to store the value or not.

Is this a possible race condition? Is it possible that the second action could be run before the linkcatcher handles the message?

Further, if the linkcatcher runs several actions of its own, will they all be completed prior to the above setfield action getting started?

(Yes, I ask because I am in fact looking to write an action string that begins with a message and depends on the message being completely handled for the rest of the actions to be run correctly. I am thinking of trying to devise tests, but by nature of race conditions, it’s hard to tell of the test passed because there’s no race condition, or because you got lucky.)

I belive it is asynchronous, and the triggers are started in order, but may not wait to proceed. It can also be how you reference the action(s), inside, outside or via an actions parameter of a trigger (typically a button).

  • But I leave it to the experts.

Think I should change the category to Developers?

Not an absolute proof, but the following suggests that it is synchronous. (NOTE: this is very poorly performing, deliberately!! Do not run if your computer is very old and might not be able to handle it!!!)

<$linkcatcher actions="""
<$list filter="[range[1000]]" variable="_">
<$action-setfield $field="counter" $value={{{ [all[tiddlers+shadows]search:*[tiddler]] +[{!!counter}add[1]] }}}/>
</$list>"""
>

<$button actions="""
<$action-sendmessage $message="tm-navigate" navigateTo="whatever" />
<$action-setfield $field="result" $value={{!!counter}} />
""">click</$button>

</$linkcatcher>

In the link catcher actions I have deliberately created an extremely badly performing filter to increment the “counter” field, and loop through it 1000 times.

In the button, I send a navigate message and then get the result of the counter and place it in the “result” field.

When I click the button, after a few seconds, the result field (so far) has always matched the counter field, meaning that all the long actions in the linkcatcher widget are completed before the second action in the button is run.

In fact, even if I add another link catcher around it and send another navigate message (from the inner link catcher) and (in the outer link catcher) increment the “counter” field one more time, the “result” field ultimately gets set to the same thing as the “counter” field. I think this shows that all actions that “chain-react” off of one action get completed before an action that follows the one that started off a chain.

(Additionally, the fact that TW hangs for several seconds after clicking the button is another indication that it is all synchronous.)

Everything in a file TW is synchronous.

Except the new WidgetMessage: tm-http-request which talks to external APIs. Those requests have to be asynchronous.