plugins: sequential promises not working

This commit is contained in:
Austen Collins 2015-10-18 16:24:44 -07:00 committed by doapp-ryanp
parent e75cc17530
commit 2ac1e06ac3
2 changed files with 21 additions and 20 deletions

View File

@ -149,13 +149,11 @@ class Jaws {
if (config && config.handler) {
_this[config.handler] = function() {
// ADD TO QUEUE?
// Add to queue
_this._queue.concat(_this.hooks[config.handler + 'Pre']);
_this._queue.push(_this.actions[config.handler].apply(_this, arguments));
_this._queue.concat(_this.hooks[config.handler + 'Post']);
console.log(_this._queue)
return _this._executeQueue();
}

View File

@ -13,6 +13,7 @@ let JAWS = require('../../lib/Jaws.js'),
utils = require('../../lib/utils'),
assert = require('chai').assert,
shortid = require('shortid'),
Promise = require('bluebird'),
config = require('../config');
/**
@ -72,16 +73,17 @@ class PromisePlugin extends JawsPlugin {
*/
_actionProjectCreate(options) {
let _this = this;
return new Promise(function(resolve, reject) {
return setTimeout(function() {
_this.Jaws.generatorPluginHookAction = true;
console.log(options);
return resolve();
}, 500);
})
var deferred = Promise.pending();
setTimeout(function() {
_this.Jaws.generatorPluginAction = true;
console.log(options);
deferred.resolve();
}, 500);
return deferred.promise;
}
_hookPreProjectCreate() {
@ -94,13 +96,14 @@ class PromisePlugin extends JawsPlugin {
_hookPostProjectCreate() {
let _this = this;
return new Promise(function(resolve, reject) {
return setTimeout(function() {
_this.Jaws.generatorPluginHookPost = true;
console.log('asjfalsjfl')
return resolve();
}, 500);
})
var deferred = Promise.pending();
setTimeout(function() {
_this.Jaws.generatorPluginHookPost = true;
console.log('post hook resolved');
deferred.resolve();
}, 500);
return deferred.promise;
}
}
@ -132,7 +135,7 @@ describe('Test Promise Plugins', function() {
.then(function() {
assert.isTrue(Jaws.generatorPluginHookPre);
assert.isTrue(Jaws.generatorPluginHookPost);
assert.isTrue(Jaws.generatorPluginHookAction);
assert.isTrue(Jaws.generatorPluginAction);
done();
})
.catch(function(e) {