是的setTimeout跨操作系统的睡眠行为/暂停界定? [英] Is the behaviour of setTimeout across an OS sleep/suspend defined?

查看:161
本文介绍了是的setTimeout跨操作系统的睡眠行为/暂停界定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了​​的setTimeout 例如10秒,这10秒中,我挂起/休眠的电脑。在觉醒,下列哪项是正确的: -

I set a setTimeout for example 10s, and during that 10s, I suspend/sleep the PC. On awaken, which of the following is true:-


  1. 超时是保证消防

  2. 超时是保证不火

  3. 超时可能会或可能不会触发。这是特定浏览器

对于重复的setInterval同样的问题。难道保证(不)继续。

Same question for a recurring setInterval. Is it guaranteed to (not) continue.

推荐答案

简答

它的定义是在规范执行。超时请求将进入各种各样的队列,并轮询,直到它可以被解雇。如果系统休眠恢复后,它会拿起它离开的地方和恢复投票。

It is defined to execute in the spec. The timeout request will go into a queue of sorts and poll until it can get fired. If the system sleeps upon resume it will pick up where it left off and resuming polling.

长的答案可能比任何人都关心知道

最近(2014年10月28日)工薪草案在书面的W3答案的时候,它会火......只要操作系统并不在临睡前/暂停和觉醒/恢复(外部范围的过程混乱向上)。它更多的是操作系统级别的问题,但至于W3规格的推移,它最终将火。

The most recent (Oct 28th, 2014) working-draft of the Timer's Spec at the time of answer as written by the w3, it will fire... so long as the OS doesn't mess-up in the process of going to sleep/suspending and waking/resuming (external to the scope). It's more of an OS level question, but as far as the w3 spec goes, it will eventually fire.

无论是的setInterval(...)的setTimeout(...)熄灭一样的 windowTimer 接口,其中窗口对象浏览器实现。

Both the setInterval(...) and setTimeout(...) go off of the same windowTimer interface which the window object for the browser implements.

在这两种情况下,客户端定义是一个区间或该方法方面经历了一个定时器初始化步骤的超时请求其中,它被添加到一个列表活动的定时器的的和的处理的则返回预定的任务的。

In both cases, The client defines either an interval or a timeout request to which the method context undergoes an timer initialization steps where it is added to a list of active timers and a handle is returned for a scheduled task.

一旦在活动的定时器的列表的,系统将排队的任务的在或时间要求的时间后执行(等待其它任务具有较高优先级,以及CPU负载)。如果一个任务无法保留CPU时间,它会轮询/等待,直到它可以。因此,如果在系统休眠恢复后,它会拿起它离开的地方。

Once in the list of active timers, the system will queue the task to execute at or after the requested duration of time (pending other tasks with higher priority as well as CPU load). If a task cannot reserve CPU time, it will poll/wait until it can. So if the system sleeps upon resume it will pick up where it left off.

为了执行任务,它的处理的必须存在的活动的定时器的列表的。运行任务之后,如果重复标志被设置为true(如果它是用的setInterval(创建...))的任务的会重新使用相同的参数,并分配了相同的完全一样的处理的。换句话说,它被加回到队列/列表以在或下一间隔之后执行。

In order for a task to execute, it's handle must exist in list of active timers. After task has run, if the repeat flag is set to true (if it was created with setInterval(...)) the task will be recreated with the same parameters and assigned the same exact same handle. In other words it gets added back into the queue/list to be executed at or after the next interval.

以下是唯一的音符或备注定时规格有关系统从活动的定时器列表中删除项目:

The following is the only note or remark in the Timer spec about the system removing items from the list of active timers:

一旦任务已被处理,如果重复标志是假的,它是安全的移除活动的定时器的列表手柄的条目(没有办法过去的这点要检测项的存在,所以它在技​​术上不重要的一种方式或其他)

Once the task has been processed, if the repeat flag is false, it is safe to remove the entry for handle from the list of active timers (there is no way for the entry's existence to be detected past this point, so it does not technically matter one way or the other)

根据规范,如果它是在活动的定时器的列表当任务运行,它会火如预期。否则将被中止。所以,回到我的第一点,如果操作系统睡眠期间不误事/暂停后恢复的任务流程的继续调查。一旦它获得CPU时间它的处理的还应该存在的 的,因而在被处理的将执行活动的定时器的列表。

According to the spec if it is in the list of active timers when the task is ran, it will fire as expected. Otherwise it is aborted. So back to my first point, if the OS doesn't mess things up during the sleep/suspend process upon resuming the task continue to poll. Once it gets CPU time it's handle should still exist in the list of active timers and thus upon being processed will execute.

这篇关于是的setTimeout跨操作系统的睡眠行为/暂停界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆