-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from danielgerlag/additional-primitives
Additional primitives
- Loading branch information
Showing
44 changed files
with
951 additions
and
455 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
export async function spinWaitCallback(until: () => Promise<boolean>, done: DoneFn) { | ||
let counter = 0; | ||
let callback = async () => { | ||
|
||
try { | ||
let result = await until(); | ||
|
||
if ((!result) && (counter < 60)) { | ||
counter++; | ||
setTimeout(callback, 500); | ||
} | ||
else { | ||
done(); | ||
} | ||
} | ||
catch (err) { | ||
done.fail(err); | ||
} | ||
}; | ||
setTimeout(callback, 500); | ||
} | ||
|
||
export function spinWait(until: () => Promise<boolean>): Promise<void> { | ||
return new Promise<void>((resolve, reject) => { | ||
let counter = 0; | ||
let callback = async () => { | ||
try { | ||
let result = await until(); | ||
|
||
if ((!result) && (counter < 60)) { | ||
counter++; | ||
setTimeout(callback, 500); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}; | ||
setTimeout(callback, 500); | ||
}); | ||
} |
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
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
Oops, something went wrong.