@@ -23,7 +23,7 @@ import { BuildFlags } from "./toolchain/BuildFlags";
2323import { SwiftToolchain } from "./toolchain/toolchain" ;
2424import { isPathInsidePath } from "./utilities/filesystem" ;
2525import { lineBreakRegex } from "./utilities/tasks" ;
26- import { execSwift , getErrorDescription , hashString } from "./utilities/utilities" ;
26+ import { execSwift , getErrorDescription , hashString , unwrapPromise } from "./utilities/utilities" ;
2727
2828/** Swift Package Manager contents */
2929export interface PackageContents {
@@ -199,7 +199,6 @@ export class SwiftPackage {
199199 private _contents : SwiftPackageState | undefined ;
200200 private contentsPromise : Promise < SwiftPackageState > ;
201201 private contentsResolve : ( value : SwiftPackageState | PromiseLike < SwiftPackageState > ) => void ;
202- private contentsReject : ( reason ?: unknown ) => void ;
203202
204203 /**
205204 * SwiftPackage Constructor
@@ -213,14 +212,9 @@ export class SwiftPackage {
213212 // TODO: Make private again
214213 public workspaceState : WorkspaceState | undefined
215214 ) {
216- let res : ( value : SwiftPackageState | PromiseLike < SwiftPackageState > ) => void ;
217- let rej : ( reason ?: unknown ) => void ;
218- this . contentsPromise = new Promise ( ( resolve , reject ) => {
219- res = resolve ;
220- rej = reject ;
221- } ) ;
222- this . contentsResolve = res ! ;
223- this . contentsReject = rej ! ;
215+ const { promise, resolve } = unwrapPromise < SwiftPackageState > ( ) ;
216+ this . contentsPromise = promise ;
217+ this . contentsResolve = resolve ;
224218 }
225219
226220 /**
@@ -381,14 +375,10 @@ export class SwiftPackage {
381375
382376 /** Reload swift package */
383377 public async reload ( folderContext : FolderContext , disableSwiftPMIntegration : boolean = false ) {
384- let res : ( value : SwiftPackageState | PromiseLike < SwiftPackageState > ) => void ;
385- let rej : ( reason ?: unknown ) => void ;
386- this . contentsPromise = new Promise ( ( resolve , reject ) => {
387- res = resolve ;
388- rej = reject ;
389- } ) ;
390- this . contentsResolve = res ! ;
391- this . contentsReject = rej ! ;
378+ const { promise, resolve } = unwrapPromise < SwiftPackageState > ( ) ;
379+ this . contentsPromise = promise ;
380+ this . contentsResolve = resolve ;
381+
392382 const loadedContents = await this . loadPackageState (
393383 folderContext ,
394384 disableSwiftPMIntegration
0 commit comments