-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
1,028 additions
and
1,698 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 |
---|---|---|
@@ -1,39 +1,41 @@ | ||
import { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; | ||
import { Address } from './Address.js'; | ||
import { ReadonlyAddress } from './ReadonlyAddress.js'; | ||
import type { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; | ||
import type { Address } from './Address.js'; | ||
import type { ReadonlyAddress } from './ReadonlyAddress.js'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class | ||
export class AddressUtil { | ||
public static await<V, A extends Address<V>>(address: ReadonlyAddress<PromiseLike<V>>, callback: UnaryFunction<Set<V>, A>): Promise<A> { | ||
export namespace AddressUtil { | ||
export const wait = <V, A extends Address<V>>(address: ReadonlyAddress<PromiseLike<V>>, callback: UnaryFunction<Set<V>, A>): Promise<A> => { | ||
if (address.isEmpty()) { | ||
return Promise.resolve(callback(new Set())); | ||
} | ||
|
||
let rejected: boolean = false; | ||
let rejected = false; | ||
const set: Set<V> = new Set(); | ||
|
||
return new Promise((resolve: Resolve<A>, reject: Reject) => { | ||
address.forEach((value: PromiseLike<V>) => { | ||
value.then((v: V) => { | ||
if (rejected) { | ||
return; | ||
} | ||
for (const value of address.values()) { | ||
value.then( | ||
(v: V) => { | ||
if (rejected) { | ||
return; | ||
} | ||
|
||
set.add(v); | ||
set.add(v); | ||
|
||
if (set.size === address.size()) { | ||
resolve(callback(set)); | ||
} | ||
}, (e: unknown) => { | ||
if (rejected) { | ||
return; | ||
} | ||
if (set.size === address.size()) { | ||
resolve(callback(set)); | ||
} | ||
}, | ||
(e: unknown) => { | ||
if (rejected) { | ||
return; | ||
} | ||
|
||
rejected = true; | ||
rejected = true; | ||
|
||
reject(e); | ||
}); | ||
}); | ||
reject(e); | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
}; | ||
} |
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.