Table of Contents

Class IdleDeadline

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The IdleDeadline interface is used as the data type of the input parameter to idle callbacks established by calling RequestIdleCallback(IdleRequestCallback, IdleRequestOptions). It offers a method, TimeRemaining(), which lets you determine how much longer the user agent estimates it will remain idle and a property, DidTimeout, which lets you determine if your callback is executing because its timeout duration expired.

[Value("IdleDeadline")]
public class IdleDeadline
Inheritance
IdleDeadline
Inherited Members

Remarks

Constructors

IdleDeadline()

public IdleDeadline()

Properties

DidTimeout

The read-only didTimeout property on the
IdleDeadline interface is a Boolean value which
indicates whether or not the idle callback is being invoked because the timeout interval
specified when RequestIdleCallback(IdleRequestCallback, IdleRequestOptions) was called has expired.

[Value("didTimeout")]
public bool DidTimeout { get; }

Property Value

bool

A Boolean which is true if the callback is running due to the callback's
timeout period elapsing or false if the callback is running because the
user agent is idle and is offering time to the callback.

Remarks

If didTimeout is true, the IdleDeadline object's
TimeRemaining() method will return
approximately 0.

Idle callbacks support the concept of a timeout in order to ensure that whatever task
they're meant to perform actually happens, even if the user agent never has enough idle
time available. Your callback will typically check the value of didTimeout
if it needs to perform an action even if the browser is too busy to grant you the time;
you should react by performing the needed task or, ideally, a minimal amount of work
that can be done to keep things moving along, then schedule a new callback to try again
to get the rest of the work done.

-Collaborative Scheduling of Background Tasks
-IdleDeadline
-RequestIdleCallback(IdleRequestCallback, IdleRequestOptions)
-CancelIdleCallback(ulong)

See also on MDN

Methods

TimeRemaining()

The timeRemaining() method
on the IdleDeadline interface returns the estimated number of
milliseconds remaining in the current idle period. The callback can call this method at
any time to determine how much time it can continue to work before it must return. For
example, if the callback finishes a task and has another one to begin, it can call
timeRemaining() to see if there's enough time to complete the next task. If
there isn't, the callback can just return immediately, or look for other work to do with
the remaining time.

[Value("timeRemaining")]
public Number TimeRemaining()

Returns

Number

A Number value (which is a floating-point number)
representing the number of milliseconds the user agent estimates are left in the current
idle period. The value is ideally accurate to within about 5 microseconds.If the IdleDeadline object's DidTimeout
property is true, this method returns zero.

Remarks

By the time timeRemaining() reaches 0, it is suggested that the callback
should return control to the user agent's event loop.

-Collaborative Scheduling of Background Tasks
-IdleDeadline
-RequestIdleCallback(IdleRequestCallback, IdleRequestOptions)
-CancelIdleCallback(ulong)

See also on MDN