mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-11 03:15:33 +00:00
refactor(web): mini-module resource for timedPromise
This commit is contained in:
parent
128b8ed132
commit
2e970140ee
3 changed files with 27 additions and 36 deletions
|
|
@ -11,24 +11,7 @@ const GestureRecognizer = require('../../../../build/index.js');
|
|||
const com = GestureRecognizer.com;
|
||||
const PathSegmenter = com.keyman.osk.PathSegmenter;
|
||||
|
||||
/**
|
||||
* Acts as a Promise-form of `setTimeout`.
|
||||
* @param {*} func A function to run after the specified amount of time.
|
||||
* @param {*} time The timeout to wait.
|
||||
* @returns {*} A `Promise` that will either resolve or reject after the specified amount of time.
|
||||
*/
|
||||
const timedPromise = (func, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
func();
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}, time);
|
||||
});
|
||||
}
|
||||
const timedPromise = require('../../resources/timedPromise.js');
|
||||
|
||||
describe("Segmentation", function() {
|
||||
// // File paths need to be from the package's / module's root folder
|
||||
|
|
|
|||
|
|
@ -7,24 +7,7 @@ const GestureRecognizer = require('../../../../build/index.js');
|
|||
const com = GestureRecognizer.com;
|
||||
const TrackedPath = com.keyman.osk.TrackedPath;
|
||||
|
||||
/**
|
||||
* Acts as a Promise-form of `setTimeout`.
|
||||
* @param {*} func A function to run after the specified amount of time.
|
||||
* @param {*} time The timeout to wait.
|
||||
* @returns {*} A `Promise` that will either resolve or reject after the specified amount of time.
|
||||
*/
|
||||
const timedPromise = (func, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
func();
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}, time);
|
||||
});
|
||||
}
|
||||
const timedPromise = require('../../resources/timedPromise.js');
|
||||
|
||||
describe("TrackedPath", function() {
|
||||
// // File paths need to be from the package's / module's root folder
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Acts as a Promise-form of `setTimeout`.
|
||||
* @param {*} func A function to run after the specified amount of time.
|
||||
* @param {*} time The timeout to wait.
|
||||
* @returns {*} A `Promise` that will either resolve or reject after the specified amount of time.
|
||||
*/
|
||||
const timedPromise = (func, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
func();
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}, time);
|
||||
});
|
||||
}
|
||||
|
||||
(function () {
|
||||
// Lets the function be available both in the browser and in Node.
|
||||
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
||||
module.exports = timedPromise;
|
||||
}
|
||||
}());
|
||||
Loading…
Add table
Reference in a new issue