lastRun()#
检索当前运行进程中上次成功完成任务的时间。对于观察程序运行时的后续任务运行最有用。
¥Retrieves the last time a task was successfully completed during the current running process. Most useful on subsequent task runs while a watcher is running.
与 src() 结合使用时,可以通过跳过自上次成功完成任务以来未更改的文件,启用增量构建来加快执行时间。
¥When combined with src(), enables incremental builds to speed up execution times by skipping files that haven't changed since the last successful task completion.
用法#
¥Usage
签名#
¥Signature
参数#
¥Parameters
| 参数 | type | note |
|---|---|---|
| 任务 (必填) | 函数 字符串 | 已注册任务的任务函数或字符串别名。 |
| precision | number | 默认:节点 v0.10 上为 1000,节点 v0.12+ 上为 0。详细内容请参见下面的 时间戳精度 部分。 |
返回#
¥Returns
时间戳(以毫秒为单位),与任务的上次完成时间相匹配。如果任务尚未运行或失败,则返回 undefined。
¥A timestamp (in milliseconds), matching the last completion time of the task. If the task has not been run or has failed, returns undefined.
为了避免缓存无效状态,如果任务出错,返回值将为 undefined。
¥To avoid an invalid state being cached, the returned value will be undefined if a task errors.
错误#
¥Errors
当使用字符串或函数以外的值调用时,会抛出错误并显示消息 "只有函数可以检查 lastRun"。
¥When called with a value other than a string or function, throws an error with the message, "Only functions can check lastRun".
当调用不可扩展函数并且 Node 缺少 WeakMap 时,会抛出错误并显示消息 "只有可扩展函数才能检查 lastRun"。
¥When called on a non-extensible function and Node is missing WeakMap, throws an error with the message, "Only extensible functions can check lastRun".
时间戳精度#
¥Timestamp precision
虽然时间戳精度有合理的默认值,但可以使用 precision 参数对它们进行舍入。如果你的文件系统或节点版本的文件时间属性精度有损,则非常有用。
¥While there are sensible defaults for the precision of timestamps, they can be rounded using the precision parameter. Useful if your file system or Node version has a lossy precision on file time attributes.
lastRun(someTask)返回 1426000001111¥
lastRun(someTask)returns 1426000001111lastRun(someTask, 100)返回 1426000001100¥
lastRun(someTask, 100)returns 1426000001100lastRun(someTask, 1000)返回 1426000001000¥
lastRun(someTask, 1000)returns 1426000001000
文件的 实时统计 精度可能会有所不同,具体取决于所使用的节点版本和/或文件系统。
¥A file's mtime stat precision may vary depending on the node version and/or the file system used.
| platform | precision |
|---|---|
| 节点 v0.10 | 1000 毫秒 |
| 节点 v0.12+ | 1 毫秒 |
| FAT32 文件系统 | 2000 毫秒 |
| HFS+ 或 Ext3 文件系统 | 1000 毫秒 |
| 使用节点 v0.10 的 NTFS | 1 秒 |
| 使用节点 0.12+ 的 NTFS | 100 毫秒 |
| 使用 Node v0.10 的 Ext4 | 1000 毫秒 |
| 使用 Node 0.12+ 的 Ext4 | 1 毫秒 |