Hey I am writing a small lib Splunk to use the ES6 feature Async/Await to communicate with the backend. But when I set the Arrow Function in the define statement define([], async () => { await smth });
it seems that it is not invoked anymore.
Here my code so far:
controller.js
require([
'../app/splunk-async/splunk-async',
], async (SplunkAsync) => {
const SA = new SplunkAsync();
const data = await SA.get('/services/authentication/users');
console.log(data)
});
splunk-async.js
//# sourceURL=splunk-async.js
define(['splunkjs/mvc'], (mvc) =>
class asyncSplunk {
constructor () {
this._service = mvc.createService();
}
/**
*
* @param {String} uri
*/
get (uri) {
return new Promise((resolve, reject) => {
const service = this._service;
service.get(uri)
.done(res => resolve(res))
.fail((data, status, err) => reject(data, status, err));
});
}
}
);
Does anyone has a solution? Thanks :)
Edit 1:
Thank you for your responses. I've tried all your suggestions. But none of them seem to work. When I wrap everything in try/catch nothing is "catched". The function Promise.promisify() does not exit. It seems that I have to tell the define function, that its body is async which I tried: async () => {}.
Any more suggestions?