|
@@ -0,0 +1,144 @@
|
|
|
+define("amber_core/Kernel-Promises", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
|
|
|
+var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
|
|
|
+$core.addPackage('Kernel-Promises');
|
|
|
+$core.packages["Kernel-Promises"].innerEval = function (expr) { return eval(expr); };
|
|
|
+$core.packages["Kernel-Promises"].transport = {"type":"amd","amdNamespace":"amber_core"};
|
|
|
+
|
|
|
+$core.addClass('Thenable', $globals.Object, [], 'Kernel-Promises');
|
|
|
+
|
|
|
+$globals.Thenable.comment="I am the abstract base class for Promises.\x0a\x0aMy subclasses should wrap existing JS implementations.\x0a\x0aI contain methods that wrap Promises/A+ `.then` behaviour.";
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "all:",
|
|
|
+protocol: 'promises',
|
|
|
+fn: function (nadicBlock){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.then(function (array) {
|
|
|
+ return nadicBlock._valueWithPossibleArguments_(array);
|
|
|
+});
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"all:",{nadicBlock:nadicBlock},$globals.Thenable)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["nadicBlock"],
|
|
|
+source: "all: nadicBlock\x0a<return self.then(function (array) {\x0a return nadicBlock._valueWithPossibleArguments_(array);\x0a})>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.Thenable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "catch:",
|
|
|
+protocol: 'promises',
|
|
|
+fn: function (aBlock){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.then(null, function (err) {
|
|
|
+ return aBlock._value_(err);
|
|
|
+});
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.Thenable)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aBlock"],
|
|
|
+source: "catch: aBlock\x0a<return self.then(null, function (err) {\x0a return aBlock._value_(err);\x0a})>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.Thenable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "on:do:",
|
|
|
+protocol: 'promises',
|
|
|
+fn: function (aClass,aBlock){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.then(null, function (err) {
|
|
|
+ if (err._isKindOf_(aClass)) return aBlock._value_(err);
|
|
|
+ else throw err;
|
|
|
+});
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.Thenable)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aClass", "aBlock"],
|
|
|
+source: "on: aClass do: aBlock\x0a<return self.then(null, function (err) {\x0a if (err._isKindOf_(aClass)) return aBlock._value_(err);\x0a else throw err;\x0a})>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.Thenable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "on:do:catch:",
|
|
|
+protocol: 'promises',
|
|
|
+fn: function (aClass,aBlock,anotherBlock){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.then(null, function (err) {
|
|
|
+ try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }
|
|
|
+ return anotherBlock._value_(err);
|
|
|
+});
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aClass", "aBlock", "anotherBlock"],
|
|
|
+source: "on: aClass do: aBlock catch: anotherBlock\x0a<return self.then(null, function (err) {\x0a try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }\x0a return anotherBlock._value_(err);\x0a})>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.Thenable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "then:",
|
|
|
+protocol: 'promises',
|
|
|
+fn: function (aBlock){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.then(function (result) {
|
|
|
+ return aBlock._value_(result);
|
|
|
+});
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"then:",{aBlock:aBlock},$globals.Thenable)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aBlock"],
|
|
|
+source: "then: aBlock\x0a<return self.then(function (result) {\x0a return aBlock._value_(result);\x0a})>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.Thenable);
|
|
|
+
|
|
|
+
|
|
|
+});
|