refactor(web): mini-module resource for timedPromise

This commit is contained in:
Joshua A. Horton 2022-09-01 08:58:47 +07:00
parent 128b8ed132
commit 2e970140ee
3 changed files with 27 additions and 36 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
}
}());