Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

async.js - Incorrect typing for `times` function?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...