实施承诺模式 [英] Implement promises pattern
问题描述
jquery
并需要算法。 伪代码:
function loadWidget(id){
list.push (ID);
//这里我应该确保所有的Widget加载
}
在其他应用程序中我调用
app.loadWidget.add(widget1.id);
。
。
。
app.loadWidget.add(widget2.id);
如果你不想准备好解决方案,想要自己实现所有的算法,然后阅读维基百科文章中引用的论文:期货和承诺以及 Promises / A 和 Promises / A + 。
要确保你'阅读你错过了Domenic Denicola的承诺点,并查看 Promises / A + 。
另一方面,如果你决定不值得重新发明轮(除非是为了教育 - 在这种情况下,尽可能多地重新创造尽可能多的车轮),然后再看一下 RSVP.js ,这是一个提供用于组织异步代码的工具的轻量级库。 RSVP.js例如由 Ember.js 使用。
I have a function that called with other objects and when my application is loaded, get parameter and the function should wait for call with all of object and then execute so with promises pattern i can ensure all object is loaded but i don't know about count of object and i don't want set timeout for loading.I don't talk about specific technology such as jquery
and need algorithm.
Pseudo Code:
function loadWidget(id){
list.push(id);
//here I should ensure all Widget is loaded
}
in other application i call
app.loadWidget.add(widget1.id);
.
.
.
app.loadWidget.add(widget2.id);
If you don't want ready solutions and instead you want to implement all of the algorithms yourself then read the papers referenced in the Wikipedia article: Futures and promises and the specs for Promises/A and Promises/A+.
And to make sure that you're doing it right, read You're Missing the Point of Promises by Domenic Denicola and see the Compliances tests for Promises/A+.
If, on the other hand, you decide that it is not worth it to reinvent the wheel (unless it is for education - in which case by all means reinvent as many wheels as possible) then take a look at RSVP.js, a lightweight library that provides tools for organizing asynchronous code. RSVP.js is used for example by Ember.js.
这篇关于实施承诺模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!