new module:ct-core /scheduler /Thread Scheduler()
Class used to improve the behaviour of applications on highly saturated machines.
When the browser becomes over saturated due to the rate of updates it receives, two problems can appear which are detrimental to the use of the browser as a real-time trading platform. These are:
- It's possible for UI events to get queued behind timer & interval events, decreasing the responsiveness of the application to user input.
- It's possible that the screen is not immediately refreshed when new updates are written to it — this can not happen until all pending JavaScript has been executed.
Members
UI _EVENT _YIELD _TIME
The time soon after which the thread scheduler will yield control so that any pending UI events can be processed.
Methods
add Thread Queue Listener(oListener)
Add a listener to be informed of updates to the current number of pending and due threads awaiting processing
Parameters:
Name | Type | Description |
---|---|---|
oListener |
module:ct-core |
The object that will receive the call-back events. |
clear Interval(nInterval Id)
A replacement for the native window.clearInterval()
method.
This method replaces, and has the same API as window.clearInterval()
— i.e. invoking window.clearInterval()
actually causes this method to be invoked.
Parameters:
Name | Type | Description |
---|---|---|
nIntervalId |
int | The id of the previously registered interval you wish to cancel. |
clear Timeout(nTimeout Id)
A replacement for the native window.clearTimeout()
method.
This method replaces, and has the same API as window.clearTimeout()
— i.e. invoking window.clearTimeout()
actually causes this method to be invoked.
Parameters:
Name | Type | Description |
---|---|---|
nTimeoutId |
int | The id of the previously registered timeout you wish to cancel. |
prevent Timer Execution After Thread(sThread Id, nTimeout)
Prevent execution of all timeouts and intervals, for the specified period of time, after a thread with the given id is executed.
The primary purpose of this method (and module:ct-core/scheduler/ThreadScheduler#preventTimerExecutionFor
) are to ensure that
JavaScript execution pauses for enough time to allow the browser to update the screen. Typically,
this will only need to occur after the execution of any display updating threads, for example
'display throttle' and 'SL4B update batcher'.
By default, ThreadScheduler
does not control the execution of UI events, and so
is unable to ensure screen refreshes occur if any long running UI events are running at the same
time. It is therefore the responsibility of application developers to ensure that any long running
UI events defer their operation using window.setTimeout()
, also bringing these threads
under the control of ThreadScheduler
.
Parameters:
Name | Type | Description |
---|---|---|
sThreadId |
String | The name of the thread after which timer execution should be prevented. |
nTimeout |
int | The number of milliseconds timer execution will be prevented for. |
prevent Timer Execution For(nTimeout)
Prevent execution of all timeouts and intervals for the specified period of time.
Parameters:
Name | Type | Description |
---|---|---|
nTimeout |
int | The number of milliseconds for which timer execution will be prevented. |
- See:
-
- preventTimerExecutionAfterThread
set Interval(fCallback, nInterval, sThread Idopt) → {int}
A replacement for the native window.setInterval()
method.
This method has the same API as window.setInterval()
, except that it
supports an optional sThreadId
parameter that helps developers visualise
thread usage, and is a pre-requisite for the use of the module:ct-core/scheduler/ThreadScheduler#preventTimerExecutionAfterThread
method. You do not need to call ThreadScheduler.setInterval()
directly
as it also replaces the native window.setInterval()
method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fCallback |
function | The function that will be invoked each time the the interval elapses. |
|
nInterval |
int | The number of milliseconds between each invocation of the call-back. |
|
sThreadId |
String |
<optional> |
A logical name for the thread that is being invoked. |
Returns:
A unique identifier that can be used to cancel this interval using module:ct-core/scheduler/ThreadScheduler#clearInterval
.
- Type
- int
set Thread Priorities(pThread Ids)
Define the priorities with which threads will be scheduled.
The following example prioritises two named threads, while another thread is explicitly de-prioritised:
ThreadScheduler.setThreadPriorities([ "highest-priority-thread", "high-priority-thread", "*", "lowest-priority-thread"]);
Parameters:
Name | Type | Description |
---|---|---|
pThreadIds |
Array | A list of thread identifiers, in priority order — a wildcard thread identifier (i.e. '*') can be used to explicitly de-prioritize any threads specified after that point. |
set Timeout(fCallback, nTimeout, sThread Idopt) → {int}
A replacement for the native window.setTimeout()
method.
This method has the same API as window.setTimeout()
, except that it
supports an optional sThreadId
parameter that helps developers visualise
thread usage, and is a pre-requisite for the use of the module:ct-core/scheduler/ThreadScheduler#preventTimerExecutionAfterThread
method. You do not need to call ThreadScheduler.setTimeout()
directly
as it also replaces the native window.setTimeout()
method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fCallback |
function | The function that will be invoked once the timeout period has elapsed. |
|
nTimeout |
int | The number of milliseconds until the call-back will be invoked. |
|
sThreadId |
String |
<optional> |
A logical name for the thread that is being invoked. |
Returns:
A unique identifier that can be used to cancel this timer using module:ct-core/scheduler/ThreadScheduler#clearTimeout
.
- Type
- int