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

View File

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