1
0
Herbert Vojčík 8 лет назад
Родитель
Сommit
2fca3e9a08
3 измененных файлов с 62 добавлено и 0 удалено
  1. 2 0
      API-CHANGES.txt
  2. 48 0
      src/Kernel-Promises.js
  3. 12 0
      src/Kernel-Promises.st

+ 2 - 0
API-CHANGES.txt

@@ -26,6 +26,8 @@
   + forBlock:
   + value:
   + signal:
+  + all:
+  + any:
 
 
 0.14.18:

+ 48 - 0
src/Kernel-Promises.js

@@ -200,6 +200,54 @@ $globals.Thenable);
 
 $core.addClass('Promise', $globals.Thenable, [], 'Kernel-Promises');
 
+$core.addMethod(
+$core.method({
+selector: "all:",
+protocol: 'composites',
+fn: function (aCollection){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Promise.all($recv(aCollection)._asArray());
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"all:",{aCollection:aCollection},$globals.Promise.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aCollection"],
+source: "all: aCollection\x0a\x22Returns a Promise resolved with results of sub-promises.\x22\x0a<return Promise.all($recv(aCollection)._asArray())>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.Promise.klass);
+
+$core.addMethod(
+$core.method({
+selector: "any:",
+protocol: 'composites',
+fn: function (aCollection){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Promise.race($recv(aCollection)._asArray());
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"any:",{aCollection:aCollection},$globals.Promise.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aCollection"],
+source: "any: aCollection\x0a\x22Returns a Promise resolved with first result of sub-promises.\x22\x0a<return Promise.race($recv(aCollection)._asArray())>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.Promise.klass);
+
 $core.addMethod(
 $core.method({
 selector: "forBlock:",

+ 12 - 0
src/Kernel-Promises.st

@@ -74,6 +74,18 @@ Thenable subclass: #Promise
 	instanceVariableNames: ''
 	package: 'Kernel-Promises'!
 
+!Promise class methodsFor: 'composites'!
+
+all: aCollection
+"Returns a Promise resolved with results of sub-promises."
+<return Promise.all($recv(aCollection)._asArray())>
+!
+
+any: aCollection
+"Returns a Promise resolved with first result of sub-promises."
+<return Promise.race($recv(aCollection)._asArray())>
+! !
+
 !Promise class methodsFor: 'instance creation'!
 
 forBlock: aBlock