可取消承诺的状态 [英] Status of cancellable promises

查看:16
本文介绍了可取消承诺的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://github.com/promises-aplus/cancellation-spec 上最古老的问题是 (在撰写本文时)9 个月大.我真的找不到关于标准"承诺取消功能的可靠信息来源.

The oldest issue on https://github.com/promises-aplus/cancellation-spec is (at the time of writing) 9 months old. I really can’t found a reliable source of information about cancellation features on ‘standard’ promises.

现在看起来该功能是在 bluebird 中实现的,但作为库开发人员,我不想弄乱我的包具有完整的承诺实现.

By now looks like the feature is implemented in bluebird, but as a library developer I don’t want to clutter my package with a full promise implementation.

我想做的只是传递一个类似 promise 的内容并支持取消规范.

What I’d like to do is simply pass a promise-like and support the cancellation-spec.

在哪里可以找到这些信息?

Where could I find this information?

推荐答案

可取消的 promise 不会出现在 ES6 中,因为 ES6 的 promise 非常少.

Cancellable promises are not going to be in ES6, as ES6 promises are very minimal.

Promises/A+ 领域的取消工作已经停滞,因为我们在等待库的进化来证明一种明显优越的方法.最新的想法是在这个问题,这是大多数图书馆希望看到的实现取消似乎随之而来(或多或少).关键点是:

Work on cancellation in the Promises/A+ space has stalled, as we wait for library evolution to prove one approach clearly superior. The latest thinking is at this issue, which is what most libraries looking to implement cancellation seem to follow (more or less). The key points are:

  • 取消作为拒绝的特殊情况
  • 对取消的反应在链中向上传播,而拒绝本身则向下传播.

简单地传递类似承诺并支持取消规范"的含义尚不清楚.您是否正在尝试生成 thenables,假设您的库的使用者会投射它,但之后会以某种方式继承一些取消行为?这有点棘手,特别是因为取消通常取决于用于拒绝承诺的指定 Cancellation 构造函数.如果取消生态系统更加发达,那么实现这一点的方式可能会更加直接.

It's not clear what you mean by "simply pass a promise-like and support the cancellation-spec." Are you trying to produce thenables, under the assumption that consumers of your library will cast it, but somehow inherit some cancellation behavior afterward? That'd be a bit tricky, especially since cancellation generally depends on a specified Cancellation constructor used for rejecting the promise. If the cancellation ecosystem was more developed, the way to do this would likely be more straightforward.

至于未来,嗯,它在不断变化!一种前进的方式是让某人支持 Promises/A+ 空间中取消提案的演变,从 Q、RSVP、when 和 Bluebird 等主要库中获得实施者的支持.然后许多较小的图书馆可能会购买,并且您可能会拥有一些可以依赖的东西.如果证明它很受欢迎,它可能也会被考虑用于 ECMAScript 承诺!

As for the future, well, it's in flux! One route forward would be for someone to champion an evolution of that cancellation proposal in Promises/A+ space, getting implementer buy-in from major libraries like Q, RSVP, when, and Bluebird. Then a lot of the smaller libraries would likely buy in, and you'd have something you could probably depend on. If it proves that popular, it'd probably be considered for ECMAScript promises as well!

但这取决于很多人做了很多工作,所以我们会看看它是否会发生:).在基本的 Promises/A+ 规范中发生这种情况真是一个奇迹,但谁知道呢……它可能会再次发生!

But that depends on a lot of people doing a lot of work, so we'll see if it happens :). It was kind of a miracle for it to happen with the base Promises/A+ spec, but who knows... it could happen again!

这篇关于可取消承诺的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆