jFactory > Reference > Traits > TraitTimeout
TraitTimeout
Registers timeouts that will be automatically stopped and removed at Remove Phase. The timeouts are wrapped by JFactoryPromise
which makes them awaitable, thenable and expirable.
Registry
myComponent.$.timeouts
Injected Methods
$timeout(registryId {string}, delay {number} [, callback {function}, [, ...handlerArguments]])
Returns: JFactoryPromise
Defers current Phase: This method registers a Task that blocks the resolution of the current Phase (if any) until the whole Task chain (including subpromises) is resolved.
Auto completed: The promise chain is completed and expired as soon as all subpromises are resolved. This behavior can be disabled by setting
anyPromiseOfTheChain.$chain.chainConfig.chainAutoComplete = false
before the promise chain is completed.
Auto removed: This Subscription is removed as soon as its Promise Chain is completed.
-
Promise syntax:
myComponent.$timeout("myTimeout", 1000) .then(() => myComponent.$log("ready"))
await myComponent.$timeout("myTimeout2", 1000); myComponent.$log("ready")
-
With callback and arguments
myComponent.$timeout("myTimeout", 1000, (arg1, arg2) => {}, "myArg1", "myArg2") .then(() => myComponent.$log("ready"))
$timeoutRemove(registryId {string} [, reason {string} = "$timeoutRemove()"])
Expires and removes the timeout registered with the key registryId
previously created by $timeout()
. An optional reason
can be given for debugging the expired Promise Chain.
$timeoutRemoveAll(removePhase)
(Automatically called at Remove Phase)
Expires and removes any timer previously created by $timeout()
if their Remove Phase match the given removePhase
.