simplofy the promise chain

This commit is contained in:
2016-06-06 16:59:13 -07:00
parent 5954ee1d51
commit 78871f97d9

View File

@@ -49,17 +49,15 @@ export default class Job extends events.EventEmitter {
if (options.headers) indexParams.headers = options.headers;
this.ready = createIndex(this.client, this.index, this.doctype)
.then(() => {
return this.client.index(indexParams)
.then((doc) => {
this.document = {
id: doc._id,
type: doc._type,
version: doc._version,
};
this.debug(`Job created in index ${this.index}`);
this.emit('created', this.document);
});
.then(() => this.client.index(indexParams))
.then((doc) => {
this.document = {
id: doc._id,
type: doc._type,
version: doc._version,
};
this.debug(`Job created in index ${this.index}`);
this.emit('created', this.document);
})
.catch((err) => {
this.debug('Job creation failed', err);