1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

EventStore should return a promise

This commit is contained in:
Ivar Conradi Østhus 2014-10-22 17:07:09 +02:00
parent 1c864bead4
commit 303d091d7d
2 changed files with 10 additions and 6 deletions

View File

@ -1,10 +1,10 @@
var util = require('util'); var Promise = require('bluebird'),
var EventEmitter = require('events').EventEmitter; util = require('util'),
EventEmitter = require('events').EventEmitter;
function EventStore() { function EventStore() {
EventEmitter.call(this); EventEmitter.call(this);
} }
util.inherits(EventStore, EventEmitter); util.inherits(EventStore, EventEmitter);
EventStore.prototype.create = function (eventType, user, eventData) { EventStore.prototype.create = function (eventType, user, eventData) {
@ -16,7 +16,10 @@ EventStore.prototype.create = function (eventType, user, eventData) {
data: eventData data: eventData
}; };
return new Promise(function (resolve, reject) {
this.emit(event.type, event); this.emit(event.type, event);
resolve();
}.bind(this));
}; };
module.exports = new EventStore(); module.exports = new EventStore();

View File

@ -29,8 +29,9 @@ module.exports = function (app) {
//Todo: error-msg: feature name is already in use //Todo: error-msg: feature name is already in use
res.status(403).end(); res.status(403).end();
} else { } else {
eventStore.create(eventType.featureCreated, user, newFeature); eventStore.create(eventType.featureCreated, user, newFeature).then(function() {
res.status(201).end(); res.status(201).end();
});
} }
}); });
}); });