[modules] Support promise

This commit is contained in:
Pooya Parsa 2017-05-11 23:34:50 +04:30
parent 336ebd4959
commit b701424aae

View File

@ -99,12 +99,15 @@ class Module {
} }
// Call module with `this` context and pass options // Call module with `this` context and pass options
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
return module.call(this, options, err => { const result = module.call(this, options, err => {
if (err) { if (err) {
return reject(err) return reject(err)
} }
resolve(module) resolve(module)
}) })
if (result && result.then instanceof Function) {
return result.then(resolve)
}
}) })
} }
} }