Methods
now() → {number}
#
Obtain the current timestamp
This is a separate function because that makes it easier to replace when testing
- Source:
Returns:
Current timestamp in milliseconds
- Type
- number
Obtain the current timestamp
This is a separate function because that makes it easier to replace when testing
postpone(callback, delay) → {number}
#
Make a postponed call.
This is a separate function because that makes it easier to replace when testing
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The function to call |
delay |
number | Delay before running callback |
- Source:
Returns:
Unique postponed timeout id
- Type
- number
schedule(immediateAction, completionTest, [delayHint]) → {jQuery.Promise}
#
Perform an action and await a callback when its side-effects are complete
The ultimate definition of "side-effects are complete" is "when the chain of async actions / setTimeout calls spawned by the action finish". This is intended to be a way to wrap non-promise code in promises and have it mostly work.
As currently implemented, we use completionTest as our sole signal. This is not guaranteed to remain true. Don't write code that assumes completionTest will be called, or which tests for a completely unrelated condition.
The signature of this function is designed to let you leave signals about your intent. You pass the action with side-effects in, and explain the conditions that must be met for further actions to be taken.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
immediateAction |
function | Action to take whose status we want to track |
|
completionTest |
function | Tests whether action is complete; ideally very cheap; there's no guarantee that we will ever call this, if we can sense completion in some other way |
|
delayHint |
number |
optional |
Optional hint about how long to wait between tests |
- Source:
Returns:
Promise that resolves when the completionTest returns true.
Note that this could already be resolved when it's returned, so there's no
guarantee that your done
call on it will be delayed.
- Type
- jQuery.Promise
Perform an action and await a callback when its side-effects are complete
The ultimate definition of "side-effects are complete" is "when the chain of async actions / setTimeout calls spawned by the action finish".