【问题标题】:Is it possible to use setTimout in Web Worker on ChromeCast是否可以在 ChromeCast 上的 Web Worker 中使用 setTimeout
【发布时间】:2014-12-16 18:11:41
【问题描述】:

我正在尝试使用 JavaScripts WebWorkers 和 setTimeout 在 ChromeCast 应用程序上设置异步超时。 这是在 jQuery 内部使用的,但是对异步 javascript 文件的调用在 jQuery 之外。

这是最小的示例(没有 jquery 并且独立工作):

索引html:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<script>
    function func(){
        console.log("start");
        var worker = new Worker('timer.js'); //External script
        worker.onmessage = function(event) {    //Method called by external script
            console.log("10s later");

        };
    }
</script>
<body onload="func()">

</body>
</html>

timer.js:

setTimeout(continueExecution, 10000) //wait ten seconds before continuing
function continueExecution()
{
    postMessage(null);
}

回调在 chromecast 和 jQuery 中工作,但在没有 10 秒延迟的情况下立即执行。

有谁知道 chromecast 如何处理超时?

【问题讨论】:

    标签: javascript jquery settimeout chromecast


    【解决方案1】:

    setTimeout 确实适用于 Chromecast,您可以查看我们的 reference receiver,它在多个地方使用了该方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      相关资源
      最近更新 更多