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

Categories

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

javascript - Regarding Promises/A+ Specification, is a promise ever allowed to never resolve or reject?

In the Promises/A+ standard, I am wondering if a promise needs to resolve or reject eventually. By this I mean a promise X with the property that under no condition whatsoever will X get resolved or rejected.

Promises/A+ states

  1. When pending, a promise:

    i. may transition to either the fulfilled or rejected state.

It is the may part that is the ambigious too me. I do not know whether to read it as saying "It may transition but may not" or that it will transition eventually and it may transition to fulfilled or rejected.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

No, the spec does not mandate this. There is no restriction on how long a promise should take to settle. And that includes an infinitely long time - known as a never-resolving/never-settling promise or forever-pending promise. (see also promise terminology)
The term may is used deliberately here, and does carry the conventional meaning.

There even exist promise implementations that offer a Promise.never primitive (e.g. in creed) to optimise the memory consumption for the case when you know that your promise won't settle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...