simplofy the promise chain
This commit is contained in:
20
src/job.js
20
src/job.js
@@ -49,17 +49,15 @@ export default class Job extends events.EventEmitter {
|
|||||||
if (options.headers) indexParams.headers = options.headers;
|
if (options.headers) indexParams.headers = options.headers;
|
||||||
|
|
||||||
this.ready = createIndex(this.client, this.index, this.doctype)
|
this.ready = createIndex(this.client, this.index, this.doctype)
|
||||||
.then(() => {
|
.then(() => this.client.index(indexParams))
|
||||||
return this.client.index(indexParams)
|
.then((doc) => {
|
||||||
.then((doc) => {
|
this.document = {
|
||||||
this.document = {
|
id: doc._id,
|
||||||
id: doc._id,
|
type: doc._type,
|
||||||
type: doc._type,
|
version: doc._version,
|
||||||
version: doc._version,
|
};
|
||||||
};
|
this.debug(`Job created in index ${this.index}`);
|
||||||
this.debug(`Job created in index ${this.index}`);
|
this.emit('created', this.document);
|
||||||
this.emit('created', this.document);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.debug('Job creation failed', err);
|
this.debug('Job creation failed', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user