mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
use new task scheduling api if available
about 2% faster than the worker-based yield function
This commit is contained in:
parent
b0d20cee00
commit
2f65f9d6d1
1 changed files with 11 additions and 0 deletions
11
src/main.js
11
src/main.js
|
|
@ -114,6 +114,17 @@ if(typeof process !== "undefined")
|
|||
v86.prototype.register_yield = function() {};
|
||||
v86.prototype.unregister_yield = function() {};
|
||||
}
|
||||
else if(window["scheduler"] && typeof window["scheduler"]["postTask"] === "function" && !location.href.includes("dont-use-scheduling-api"))
|
||||
{
|
||||
v86.prototype.yield = function(t, tick)
|
||||
{
|
||||
t = Math.max(0, t);
|
||||
window["scheduler"]["postTask"](() => this.yield_callback(tick), { delay: t });
|
||||
};
|
||||
|
||||
v86.prototype.register_yield = function() {};
|
||||
v86.prototype.unregister_yield = function() {};
|
||||
}
|
||||
else if(typeof Worker !== "undefined")
|
||||
{
|
||||
// XXX: This has a slightly lower throughput compared to window.postMessage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue