1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Add async setImmediate util

Adds an async/promise-based version of `setImmediate`. Note that, despite being
poorly adopted, `setImmediate` is polyfilled, and should be more performant
than `sleep(0)`.

Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
This commit is contained in:
Clark Fischer
2023-01-16 07:35:23 -08:00
parent a34d06c7c2
commit ddce1bcd28
2 changed files with 45 additions and 3 deletions

View File

@@ -1,3 +1,19 @@
/*
Copyright 2023 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.
*/
import * as utils from "../../src/utils";
import {
alphabetPad,
@@ -587,4 +603,22 @@ describe("utils", function () {
expect(utils.isSupportedReceiptType("this is a receipt type")).toBeFalsy();
});
});
describe("sleep", () => {
it("resolves", async () => {
await utils.sleep(0);
});
it("resolves with the provided value", async () => {
const expected = Symbol("hi");
const result = await utils.sleep(0, expected);
expect(result).toBe(expected);
});
});
describe("immediate", () => {
it("resolves", async () => {
await utils.immediate();
});
});
});