Browse Source

Add model do: [ ... ] to Promise new: ... .

You can do

Promise new: [ :model |
   "possibly async, later:"
   model do: [ ... some code ... ]
].

and the promise is resolved with the result of the block
and is rejected when there is error during its execution.

Just a convenient shortcut `model value: (Promise forBlock: [ ... ])`.
Herby Vojčík 3 years ago
parent
commit
bd176d5428
4 changed files with 26 additions and 4 deletions
  1. 8 0
      CHANGELOG
  2. 6 0
      lang/API-CHANGES.txt
  3. 7 3
      lang/src/Kernel-Promises.js
  4. 5 1
      lang/src/Kernel-Promises.st

+ 8 - 0
CHANGELOG

@@ -1,3 +1,11 @@
+7 Oct 2020 - Release 0.29.4
+===================================
+
+* Convenient method for model pass to Promise new: block
+
+Commits: https://lolg.it/amber/amber/commits/0.29.4.
+
+
 3 Oct 2020 - Release 0.29.3
 3 Oct 2020 - Release 0.29.3
 ===================================
 ===================================
 
 

+ 6 - 0
lang/API-CHANGES.txt

@@ -1,3 +1,9 @@
+0.29.4:
+
++ (model in `Promise new: [ :model | ]`) >>
+  + do:
+
+
 0.29.3:
 0.29.3:
 
 
 * Deprecate TestCase >> debugCase.
 * Deprecate TestCase >> debugCase.

+ 7 - 3
lang/src/Kernel-Promises.js

@@ -145,10 +145,10 @@ selector: "new:",
 protocol: "instance creation",
 protocol: "instance creation",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aBlock"],
 args: ["aBlock"],
-source: "new: aBlock\x0a\x22Returns a Promise that is eventually resolved or rejected.\x0aPass a block that is called with one argument, model.\x0aYou should call model value: ... to resolve the promise\x0aand model signal: ... to reject the promise.\x0aIf error happens during run of the block,\x0apromise is rejected with that error as well.\x22\x0a<inlineJS: 'return new Promise(function (resolve, reject) {\x0a    var model = {value: resolve, signal: reject};\x0a    aBlock._value_(model);\x0a})'>",
+source: "new: aBlock\x0a\x22Returns a Promise that is eventually resolved or rejected.\x0aPass a block that is called with one argument, model.\x0aYou should call model value: ... to resolve the promise\x0aand model signal: ... to reject the promise.\x0aIf error happens during run of the block,\x0apromise is rejected with that error as well.\x22\x0a<inlineJS: 'return new Promise(function (resolve, reject) {\x0a    var model = {\x0a\x09\x09value: resolve,\x0a\x09\x09signal: reject,\x0a\x09\x09do: function (aBlock) { resolve($self._forBlock_(aBlock)); }\x0a\x09};\x0a    aBlock._value_(model);\x0a})'>",
 referencedClasses: [],
 referencedClasses: [],
 //>>excludeEnd("ide");
 //>>excludeEnd("ide");
-pragmas: [["inlineJS:", ["return new Promise(function (resolve, reject) {\x0a    var model = {value: resolve, signal: reject};\x0a    aBlock._value_(model);\x0a})"]]],
+pragmas: [["inlineJS:", ["return new Promise(function (resolve, reject) {\x0a    var model = {\x0a\x09\x09value: resolve,\x0a\x09\x09signal: reject,\x0a\x09\x09do: function (aBlock) { resolve($self._forBlock_(aBlock)); }\x0a\x09};\x0a    aBlock._value_(model);\x0a})"]]],
 messageSends: []
 messageSends: []
 }, function ($methodClass){ return function (aBlock){
 }, function ($methodClass){ return function (aBlock){
 var self=this,$self=this;
 var self=this,$self=this;
@@ -156,7 +156,11 @@ var self=this,$self=this;
 return $core.withContext(function($ctx1) {
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
 return new Promise(function (resolve, reject) {
 return new Promise(function (resolve, reject) {
-    var model = {value: resolve, signal: reject};
+    var model = {
+		value: resolve,
+		signal: reject,
+		do: function (aBlock) { resolve($self._forBlock_(aBlock)); }
+	};
     aBlock._value_(model);
     aBlock._value_(model);
 });
 });
 return self;
 return self;

+ 5 - 1
lang/src/Kernel-Promises.st

@@ -40,7 +40,11 @@ and model signal: ... to reject the promise.
 If error happens during run of the block,
 If error happens during run of the block,
 promise is rejected with that error as well."
 promise is rejected with that error as well."
 <inlineJS: 'return new Promise(function (resolve, reject) {
 <inlineJS: 'return new Promise(function (resolve, reject) {
-    var model = {value: resolve, signal: reject};
+    var model = {
+		value: resolve,
+		signal: reject,
+		do: function (aBlock) { resolve($self._forBlock_(aBlock)); }
+	};
     aBlock._value_(model);
     aBlock._value_(model);
 })'>
 })'>
 !
 !