send in time?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Zax
Posts: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

send in time?

Post by Zax » Wed Apr 10, 2024 8:51 am

Hello,

Just to be sure, do the following scripts do the exact same things, at the same time?

Code: Select all

on myProcess_A
	send "myProcess_B" to me in 100 milliseconds
end myProcess_A

on myProcess_B
	put the date into fld 1
end myProcess_B

Code: Select all

on myProcess
	wait 100 milliseconds with messages
	put the date into fld 1
end myProcess

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: send in time?

Post by LCMark » Wed Apr 10, 2024 10:01 am

@Zax:

Assuming nothing else is going on (i.e. no messages are sent during the wait) then yes they will do the same thing.

However, you will not see quite the same result if a message is handled in that 100ms window which also calls wait:

This code will cause 'the date' to populate field 1 after 1 second - not 100 milliseconds.

Code: Select all

on myProcess
        send "imitateWaitingButtonPress" to me in 50 milliseconds
	wait 100 milliseconds with messages
	put the date into fld 1
end myProcess

on imitateWaitingButtonPress
    wait 1s with messages
end imitateWaitingButtonPress
This code will cause 'the date' to populate field 1 after 100 milliseconds:

Code: Select all

on myProcess_A
        send "imitateWaitingButtonPress" to me in 50 milliseconds
   
	send "myProcess_B" to me in 100 milliseconds
end myProcess_A

on myProcess_B
	put the date into fld 1
end myProcess_B

on imitateWaitingButtonPress
    wait 1s with messages
end imitateWaitingButtonPress
The reason is that waiting is recursive.

In the myProcess handler the 'wait' has to finish before the 'put' will execute - and wait only finishes when all handlers which have been called while the wait is happening (due to messages being handled) have finished.

In the myProcess_A handler - there is no (recursive) wait - so myProcess_A finishes as soon as the second send is done. Then the imitateWaitingButtonPress message will fire, and it will wait - but because that wait is with messages the myProcess_B pending message will still be handled at the expected time - just 'inside' the wait 1s.

Zax
Posts: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: send in time?

Post by Zax » Wed Apr 10, 2024 10:49 am

Thank you LCMark for this precise and complete response.
In the specific case of launching a standalone, in which I have to wait for large substacks to load, what kind of script do you recommend?

---------------------------- kind A

Code: Select all

on preOpenStack
	insert the script of stack "CustomErrorReport" into front
	insert the script of stack "MyLib" into back
	start using stack "BigImagesLib"
	
	send "preOpenStack_readPrefs" to me in 100 milliseconds // to be sure libs will be loaded
end preOpenStack

on preOpenStack_readPrefs
	... read a prefs file if any
end preOpenStack_readPrefs

---------------------------- kind B

Code: Select all

on preOpenStack
	insert the script of stack "CustomErrorReport" into front
	insert the script of stack "MyLib" into back
	start using stack "BigImagesLib"
	
	wait 100 milliseconds with messages // to be sure libs will be loaded
	
	... read a prefs file if any
end preOpenStack

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”