Using async for polling.
This commit is contained in:
parent
10b78acb3d
commit
caf445cae7
2 changed files with 6 additions and 4 deletions
|
@ -66,7 +66,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
|||
if (isBrowser()) {
|
||||
// On the first load, check the unreads
|
||||
this.requestNotificationPermission();
|
||||
await this.fetchUnreads();
|
||||
this.fetchUnreads();
|
||||
this.requestNotificationPermission();
|
||||
|
||||
document.addEventListener("mouseup", this.handleOutsideMenuClick);
|
||||
|
@ -408,7 +408,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
|||
return amAdmin() || moderatesS;
|
||||
}
|
||||
|
||||
async fetchUnreads() {
|
||||
fetchUnreads() {
|
||||
poll(async () => {
|
||||
const auth = myAuth();
|
||||
if (auth) {
|
||||
|
|
|
@ -1499,6 +1499,8 @@ function sleep<T>(millis: number): Promise<T> {
|
|||
/**
|
||||
* Polls / repeatedly runs a promise, every X milliseconds
|
||||
*/
|
||||
export function poll(promiseFn: any, millis: number) {
|
||||
promiseFn().then(sleep(millis).then(() => poll(promiseFn, millis)));
|
||||
export async function poll(promiseFn: any, millis: number) {
|
||||
await promiseFn();
|
||||
await sleep(millis);
|
||||
return poll(promiseFn, millis);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue