add mkAsync function

This commit is contained in:
ansuz 2019-06-25 11:13:03 +02:00
parent d16aa7de8a
commit 4b8a8fbe5f
2 changed files with 25 additions and 1 deletions

View File

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

View File

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