-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move zone wait function to utils folder
- Loading branch information
1 parent
09ba6e7
commit fa9faf8
Showing
3 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { firstValueFrom, isObservable, Observable } from 'rxjs'; | ||
|
||
declare const Zone: any; | ||
|
||
export async function waitFor<T>(prom: Promise<T> | Observable<T>): Promise<T> { | ||
if (isObservable(prom)) { | ||
prom = firstValueFrom(prom); | ||
} | ||
const macroTask = Zone.current.scheduleMacroTask( | ||
`AnalogContentResolve-${Math.random()}`, | ||
() => {}, | ||
{}, | ||
() => {} | ||
); | ||
return prom.then((p: T) => { | ||
macroTask.invoke(); | ||
return p; | ||
}); | ||
} |