Skip to content

Commit a302f44

Browse files
committed
added: SchemaBuilderEntity $async([callback])
1 parent dfc21e7 commit a302f44

4 files changed

Lines changed: 119 additions & 15 deletions

File tree

builders.js

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,55 @@ SchemaBuilderEntity.prototype.$make = function(obj) {
548548

549549
var self = this;
550550

551+
obj.$async = function(callback) {
552+
if (callback === undefined)
553+
callback = NOOP;
554+
obj.$$async = [];
555+
obj.$callback = callback;
556+
setImmediate(function() {
557+
obj.$$async.async(callback);
558+
});
559+
return obj;
560+
};
561+
551562
obj.$save = function(helper, callback) {
552-
return self.save(obj, helper, callback);
563+
564+
if (!obj.$$async) {
565+
self.save(obj, helper, callback);
566+
return obj;
567+
}
568+
569+
obj.$$async.push(function(next) {
570+
self.save(obj, helper, function(err, result) {
571+
if (!err)
572+
return next();
573+
obj.$$async = null;
574+
next = null;
575+
obj.$callback(err);
576+
});
577+
});
578+
579+
return obj;
553580
};
554581

555582
obj.$remove = function(helper, callback) {
556-
return self.remove(callback === undefined ? obj : helper, callback);
583+
584+
if (!obj.$$async) {
585+
self.remove(helper, callback);
586+
return obj;
587+
}
588+
589+
obj.$$async.push(function(next) {
590+
self.remove(obj, helper, function(err, result) {
591+
if (!err)
592+
return next();
593+
obj.$$async = null;
594+
next = null;
595+
obj.$callback(err);
596+
});
597+
});
598+
599+
return obj;
557600
};
558601

559602
obj.$default = function() {
@@ -565,15 +608,63 @@ SchemaBuilderEntity.prototype.$make = function(obj) {
565608
};
566609

567610
obj.$transform = function(name, helper, callback) {
568-
return self.transform(name, obj, helper, callback);
611+
612+
if (!obj.$$async) {
613+
self.transform(name, obj, helper, callback);
614+
return obj;
615+
}
616+
617+
obj.$$async.push(function(next) {
618+
self.transform(name, obj, helper, function(err, result) {
619+
if (!err)
620+
return next();
621+
obj.$$async = null;
622+
next = null;
623+
obj.$callback(err);
624+
});
625+
});
626+
627+
return obj;
569628
};
570629

571630
obj.$compose = function(name, helper, callback) {
572-
return self.compose(name, obj, helper, callback);
631+
632+
if (!obj.$$async) {
633+
self.compose(name, obj, helper, callback);
634+
return obj;
635+
}
636+
637+
obj.$$async.push(function(next) {
638+
self.compose(name, obj, helper, function(err, result) {
639+
if (!err)
640+
return next();
641+
obj.$$async = null;
642+
next = null;
643+
obj.$callback(err);
644+
});
645+
});
646+
647+
return obj;
573648
};
574649

575650
obj.$workflow = function(name, helper, callback) {
576-
return self.workflow(name, obj, helper, callback);
651+
652+
if (!obj.$$async) {
653+
self.workflow(name, obj, helper, callback);
654+
return obj;
655+
}
656+
657+
obj.$$async.push(function(next) {
658+
self.workflow(name, obj, helper, function(err, result) {
659+
if (!err)
660+
return next();
661+
obj.$$async = null;
662+
next = null;
663+
obj.$callback(err);
664+
});
665+
});
666+
667+
return obj;
577668
};
578669

579670
obj.$clean = function() {
@@ -1230,6 +1321,9 @@ SchemaBuilderEntity.prototype.clean = function(m, isCopied) {
12301321

12311322
var self = this;
12321323

1324+
delete model['$$async'];
1325+
delete model['$async'];
1326+
delete model['$callback'];
12331327
delete model['$transform'];
12341328
delete model['$workflow'];
12351329
delete model['$destroy'];

minify/merged/total.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)