The typing for the times
function is:
export function times<T, E = Error>(n: number, iterator: AsyncResultIterator<number, T, E>): Promise<T>;
I read this as saying that times
expects an async function with type T
and will return a promise of a T
.
However, the documentation says that times
"accumulates results in the same manner" as map
.
I assume this means that each of the n
evaluations of the async function
will be collected into an array and returned.
This suggests that it should
return a promise of an array.
For comparison, the corresponding map
declaration is:
export function map<T, R, E = Error>(arr: T[] | IterableIterator<T> | Dictionary<T>, iterator: AsyncResultIterator<T, R, E>): Promise<R[]>;
which makes sense: it's returning a promise of an array of the return type of the iterable.
Why doesn't times
return a similar promise? Is this broken or am I misunderstanding
the semantics of times
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…