Timeout

About

This class provides an easy way to test if a certain amount of time has passed, with millisecond accuracy.

API

constructor()

constructor(duration : Integer)
constructor(duration : Text)

Creates an object whose .expired() function returns true after a given amount of time has elapsed.

If duration is an integer, it is treated as milliseconds. If duration is a string, it may contain a suffix (with or without preceding spaces) to indicate the units:

  • ms - milliseconds
  • s - seconds
  • m - minutes

If duration is a string and no suffix is provided, it defaults to "ms".


.expired

.expired : Boolean

true if the duration given in the constructor has elapsed. This property is read-only.

Example

$timeout:=cs.js.Timeout.new("2s") // 2 seconds
$done:=False

While(Not($done) && Not($timeout.expired))
  // Do something that sets $done
End while
  
If ($timeout.expired)
  // Oops, we timed out before getting it done
Else
  // Success!
End if
Last Updated:
Contributors: Aparajita