Promise<VirtualFile> () { synchronized (myLock) { return switch (getState()) { case DOWNLOADING_NOT_STARTED -> { startDownloading(); yield createDownloadedCallback(this); } case DOWNLOADING_IN_PROGRESS -> createDownloadedCallback(this); case DOWNLOADED -> Promises.resolvedPromise(myLocalVirtualFile); case ERROR_OCCURRED -> rejectedPromise("errorOccurred"); }; } }