Skip to content

Commit

Permalink
feat(util): until functions
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and alimd committed Jan 30, 2023
1 parent a7b1fb3 commit 3b17ef2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/util/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './until.js';
15 changes: 15 additions & 0 deletions core/util/src/until.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function untilEvent(element: Element, eventName: string): Promise<Event> {
return new Promise((resolve) => element.addEventListener(eventName, resolve));
}

export function delay(duration: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, duration));
}

export function untilNextFrame(): Promise<DOMHighResTimeStamp> {
return new Promise((resolve) => requestAnimationFrame(resolve));
}

export function untilIdle(timeout?: number): Promise<IdleDeadline> {
return new Promise((resolve) => requestIdleCallback(resolve, {timeout}));
}

0 comments on commit 3b17ef2

Please sign in to comment.