Life-time and mutation-time

'Execute Control': command { } => update .'Last Control' = ensure 'Executing' ( ) 
'Last Control': stategroup @default: 'Never' (
	'Never' { }
	'Executing' { 
		'Started at': number 'date-time'
		'Execution Time': number 'seconds' = . life-time .'Started at'
	}
	'Failed' {
		'At': number 'date-time'
	}
	'Success' {
		'At': number 'date-time'
	}
)

In the our UI, pressing the ‘Execute Control’ button results in an API being called and processing some financial data. This process takes about 20 seconds to finish. It will always result in either Success or Failed. To prevent users assuming nothing is happening, I wish to build in a stop-watch that illustrates the execution time.

I discovered life-time and mutation-time syntax in the documentation, but I do not yet understand it’s implication.

Can you please explain how to use both life-time and mutation-time with some examples?

Thank you in advance!

Hi Martinique,

I think you want to look at the built-in time logic:

’Started at: number ‘date-time = creation-time // gets set when state is created
‘Timeout’: number ‘date-time’ = add ( .‘Started at’, 5 ) // 5 seconds later
timer ontimeout => update ^ .‘Status’ = create ‘Timed out’ ( ) // like a command

1 Like

Thank you Rick,

I will use your construction in this case.

What are the implications of life-time and mutation-time? In what scenario’s would I use these?

Hi Martinique,

If you have a look at the documentation, you’ll find this:

as part of the node definition model/application grammar - Alan Platform - Model-Driven Software Development Platform

the mutation time is a time that gets set when the watched property gets updated

the life-time, add life-time and substract life-time can be used to watch a certain state that can be used as a sort of stopwatch. When it is set, lifetime adds up and when it gets ‘destroid’ (aka another state gets set), you can do something with the measured lifetime.

1 Like