diff --git a/packages/zowe-explorer-api/__tests__/__unit__/utils/DeferredPromise.unit.test.ts b/packages/zowe-explorer-api/__tests__/__unit__/utils/DeferredPromise.unit.test.ts index 23f86f7da..94be85edf 100644 --- a/packages/zowe-explorer-api/__tests__/__unit__/utils/DeferredPromise.unit.test.ts +++ b/packages/zowe-explorer-api/__tests__/__unit__/utils/DeferredPromise.unit.test.ts @@ -9,7 +9,7 @@ * */ -import { DeferredPromise } from "../../../src"; +import { DeferredPromise, DeferredPromiseStatus } from "../../../src"; describe("DeferredPromise constructor", () => { it("sets resolve and reject functions", () => { @@ -23,13 +23,13 @@ describe("DeferredPromise constructor", () => { describe("DeferredPromise.status", () => { it("returns pending when not yet resolved", () => { const deferred = new DeferredPromise(); - expect(deferred.status).toBe("pending"); + expect(deferred.status).toBe(DeferredPromiseStatus.Pending); }); it("returns fulfilled when resolved", () => { const deferred = new DeferredPromise(); deferred.resolve(null); - expect(deferred.status).toBe("fulfilled"); + expect(deferred.status).toBe(DeferredPromiseStatus.Fulfilled); }); it("returns rejected when rejected", async () => { @@ -41,7 +41,7 @@ describe("DeferredPromise.status", () => { } catch (err) { errorCaught = true; } - expect(deferred.status).toBe("rejected"); + expect(deferred.status).toBe(DeferredPromiseStatus.Rejected); expect(errorCaught).toBe(true); }); }); diff --git a/packages/zowe-explorer-api/src/utils/DeferredPromise.ts b/packages/zowe-explorer-api/src/utils/DeferredPromise.ts index d2f812fc5..d4f4669ee 100644 --- a/packages/zowe-explorer-api/src/utils/DeferredPromise.ts +++ b/packages/zowe-explorer-api/src/utils/DeferredPromise.ts @@ -10,7 +10,11 @@ */ /* Status of the deferred promise */ -export type DeferredPromiseStatus = "pending" | "fulfilled" | "rejected"; +export enum DeferredPromiseStatus { + Pending = "pending", + Fulfilled = "fulfilled", + Rejected = "rejected", +} /** * @brief Externally control the resolution and rejection of a promise. @@ -21,7 +25,7 @@ export type DeferredPromiseStatus = "pending" | "fulfilled" | "rejected"; * the promise's outcome depends on factors outside the immediate context. */ export class DeferredPromise { - private mStatus: DeferredPromiseStatus = "pending"; + private mStatus: DeferredPromiseStatus = DeferredPromiseStatus.Pending; public promise: Promise; public resolve: (value: T | PromiseLike) => void; @@ -30,11 +34,11 @@ export class DeferredPromise { public constructor() { this.promise = new Promise((resolve, reject) => { this.resolve = (value): void => { - this.mStatus = "fulfilled"; + this.mStatus = DeferredPromiseStatus.Fulfilled; resolve(value); }; this.reject = (err): void => { - this.mStatus = "rejected"; + this.mStatus = DeferredPromiseStatus.Rejected; reject(err); }; });