From 2df65ed446e5cc3dbd7f65d2d0ef1966ae92aef1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 13 Feb 2020 17:51:02 -0500 Subject: [PATCH] implement 'mkTimeout' method in common-util --- www/common/common-util.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/www/common/common-util.js b/www/common/common-util.js index 1af32103f..da373f1ad 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -68,6 +68,19 @@ }; }; + Util.mkTimeout = function (_f, ms) { + ms = ms || 0; + var f = Util.once(_f); + + var timeout = setTimeout(function () { + f('TIMEOUT'); + }, ms); + + return Util.both(f, function () { + clearTimeout(timeout); + }); + }; + Util.response = function () { var pending = {}; var timeouts = {};