File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import {
4444} from "./utils/storage/userPreferences" ;
4545import { getDeveloperSettings , setDeveloperSettings } from "./utils/storage/devSettings" ;
4646import { getLocalSettings , ServiceWorkerModeValues } from "./utils/storage/localSettings.js" ;
47+ import { PromiseLock } from "./utils/promiseLock.js" ;
4748type traceObj = {
4849 micros : number ;
4950 calls ?: ( string | traceObj ) [ ] ;
@@ -4477,13 +4478,15 @@ class Localuser {
44774478 this . getMemberMap . set ( uid , prom2 ) ;
44784479 return prom2 ;
44794480 }
4481+ memberLock = new PromiseLock ( ) ;
44804482 async resolvemember ( id : string , guildid : string ) : Promise < memberjson | undefined > {
44814483 if ( guildid === "@me" ) {
44824484 return undefined ;
44834485 }
44844486 const guild = this . guildids . get ( guildid ) ;
44854487 const borked = true ;
44864488 if ( ! guild || ( borked && guild . member_count > 250 ) ) {
4489+ const unlock = await this . memberLock . acquireLock ( ) ;
44874490 try {
44884491 const req = await fetch ( this . info . api + "/guilds/" + guildid + "/members/" + id , {
44894492 headers : this . headers ,
@@ -4494,6 +4497,8 @@ class Localuser {
44944497 return await req . json ( ) ;
44954498 } catch {
44964499 return undefined ;
4500+ } finally {
4501+ unlock ( ) ;
44974502 }
44984503 }
44994504 let guildmap = this . waitingmembers . get ( guildid ) ;
Original file line number Diff line number Diff line change 1+ export class PromiseLock {
2+ lastLock = Promise . resolve ( ) ;
3+ async acquireLock ( ) {
4+ const { promise, resolve : res } = Promise . withResolvers < void > ( ) ;
5+ const last = this . lastLock ;
6+ this . lastLock = promise ;
7+ await last ;
8+ return res ;
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments