2019-11-12 11:45:28 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-11-12 12:30:05 +00:00
|
|
|
// This is only here to allow access to methods like done for the time being
|
|
|
|
import Promise from "bluebird";
|
|
|
|
|
2019-11-12 11:45:28 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
// Returns a promise which resolves with a given value after the given number of ms
|
|
|
|
export const sleep = (ms: number, value: any): Promise => new Promise((resolve => { setTimeout(resolve, ms, value); }));
|
|
|
|
|
|
|
|
// Returns a Deferred
|
|
|
|
export function defer(): {resolve: () => {}, reject: () => {}, promise: Promise} {
|
|
|
|
let resolve;
|
|
|
|
let reject;
|
|
|
|
|
|
|
|
const promise = new Promise((_resolve, _reject) => {
|
|
|
|
resolve = _resolve;
|
|
|
|
reject = _reject;
|
|
|
|
});
|
|
|
|
|
|
|
|
return {resolve, reject, promise};
|
|
|
|
}
|