From 4b8a8fbe5fd91230880da146c67c0eabe97b369f Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Jun 2019 11:13:03 +0200 Subject: [PATCH] add mkAsync function --- www/assert/main.js | 17 ++++++++++++++++- www/common/common-util.js | 9 +++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/www/assert/main.js b/www/assert/main.js index 17769868d..ec69f4d5e 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -11,9 +11,10 @@ define([ '/common/flat-dom.js', '/common/media-tag.js', '/common/outer/login-block.js', + '/common/common-util.js', '/bower_components/tweetnacl/nacl-fast.min.js', -], function ($, Hyperjson, Sortify, Drive, Test, Hash, Util, Thumb, Wire, Flat, MediaTag, Block) { +], function ($, Hyperjson, Sortify, Drive, Test, Hash, Util, Thumb, Wire, Flat, MediaTag, Block, Util) { window.Hyperjson = Hyperjson; window.Sortify = Sortify; var Nacl = window.nacl; @@ -371,6 +372,20 @@ define([ return cb(true); }, "version 2 hash failed to parse correctly"); + assert(function (cb) { + var x; + var set_x = function (v) { + x = v; + }; + + Util.mkAsync(set_x)(7); + set_x(5); + + Util.mkAsync(function (expected) { + cb(x === expected); + })(7); + }, "test mkAsync"); + assert(function (cb) { Wire.create({ constructor: function (cb) { diff --git a/www/common/common-util.js b/www/common/common-util.js index 7afbf7c27..9fd2305c3 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -2,6 +2,15 @@ define([], function () { var Util = window.CryptPad_Util = {}; + Util.mkAsync = function (f) { + return function () { + var args = Array.prototype.slice.call(arguments); + setTimeout(function () { + f.apply(null, args); + }); + }; + }; + // If once is true, after the event has been fired, any further handlers which are // registered will fire immediately, and this type of event cannot be fired twice. Util.mkEvent = function (once) {