Skip to content

Commit

Permalink
docs: Added some comments regarding promise performance under async c…
Browse files Browse the repository at this point in the history
…onditions
  • Loading branch information
notheotherben committed Nov 17, 2015
1 parent d24448e commit c697682
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/lib/ModelHandlers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/ModelHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class ModelHandlers<TDocument extends { _id?: any }, TInstance> {
let wrapped: TResult;
return Bluebird.resolve(result).then((target: any) => {
return <Bluebird<TResult>>Bluebird
// If onRetrieved returns a Bluebird promise then there is no significant performance overhead here
.resolve(this.model.hooks.onRetrieved && this.model.hooks.onRetrieved(target))
.then(() => {
// Cache the document if caching is enabled
Expand All @@ -57,6 +58,7 @@ export class ModelHandlers<TDocument extends { _id?: any }, TInstance> {
creatingDocuments(documents: TDocument[]): Bluebird<any[]> {
return Bluebird.all(documents.map((document: any) => {
return Bluebird
// If onCreating returns a Bluebird promise then there is no significant performance overhead here
.resolve(this.model.hooks.onCreating && this.model.hooks.onCreating(document))
.then(() => {
document = this.model.helpers.convertToDB(document);
Expand All @@ -70,6 +72,7 @@ export class ModelHandlers<TDocument extends { _id?: any }, TInstance> {

savingDocument(instance: TInstance, changes: any): Bluebird<TInstance> {
return Bluebird
// If onSaving returns a Bluebird promise then there is no significant performance overhead here
.resolve(this.model.hooks.onSaving && this.model.hooks.onSaving(instance, changes))
.then(() => {
return instance;
Expand Down

0 comments on commit c697682

Please sign in to comment.