-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async/Await example help - can't access data in response #268
Comments
IJavascript behaves like the Node.js REPL does. That means If you need to set var data;
axios.request(config).then((req) => {data = req.data;}); If you want to print the resolved value of a const makeRequest = async (config) => {
const req = await axios.request(config);
return req.data
}
$$.sendResult(makeRequest(config)); IJavascript also offers a setting to do this automatically for every Promise, e.g.: $$.config.awaitExecution = true;
const makeRequest = async (config) => {
const req = await axios.request(config);
return req.data
}
makeRequest(config); |
Thank you! Your first example worked for me, which suffices for my purposes. However, I tried your last example too (I prefer async await syntax)
It still wouldn't work - Object.keys(result) returns an empty array, but printing result to the console clearly shows the data in the response. |
That isn't going to work. And I guess what you're after is this: var makeRequest = async (config) => {
const req = await axios.request(config);
return req.data
}
var result = makeRequest(config);
result.then(Object.keys).then(console.log); Or, since you're playing with asynchronous code, see the documentation for var makeRequest = async (config) => {
const req = await axios.request(config);
return req.data
}
var result = makeRequest(config);
$$.async();
result.then(Object.keys).then($$.sendResult); |
Can some explain how to create an async/await function in ijavascript so I can get access to the actual data?
printing data in a cell returns
So I can tell the request resolved, but then typing
returns nothing.
How do I access the actual data? I've tried JSON.parse, but that doesn't work either.
The text was updated successfully, but these errors were encountered: