OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Module "timer" | |
6 // | |
7 // This module provides basic createOneShot, createRepeating support. The | |
8 // reason to define this module is to forward calls to setTimeout, setInterval | |
9 // exposed by the browser. Mojo JS bindings are currently loaded using gin | |
10 // and createOneShot, createRepeating are not always available. | |
11 // | |
12 // TODO(crbug.com/703380): When the Mojo JS bindings move away from gin, | |
13 // this module could be removed. | |
14 | |
15 define("timer", [], function() { | |
16 /** | |
17 * Executes a function once after the set time delay. | |
18 * @param {int} delay Milliseconds to wait before executing the code. | |
19 * @callback callback | |
20 */ | |
21 function createOneShot(delay, callback) { | |
22 setTimeout(callback, delay); | |
23 } | |
24 | |
25 /** | |
26 * Repeatedly executes a function with a fixed time delay between each call. | |
27 * @param {int} delay Milliseconds to wait between executions of the code | |
28 * @callback callback | |
29 */ | |
30 function createRepeating(delay, callback) { | |
31 setInterval(callback, delay); | |
32 } | |
33 | |
34 var exports = {}; | |
35 exports.createOneShot = createOneShot; | |
36 exports.createRepeating = createRepeating; | |
37 return exports; | |
38 }); | |
OLD | NEW |