Return the Value of a function after aasy function endedHow do I return the response from an asynchronous call?Is there an “exists” function for jQuery?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueevent.preventDefault() vs. return falseWhy does ++[[]][+[]]+[+[]] return the string “10”?Copy array by valueHow do I return the response from an asynchronous call?
What are the words for people who cause trouble believing they know better?
Traffic law UK, pedestrians
Calling GPL'ed socket server inside Docker?
How can Iron Man's suit withstand this?
Pros and cons of writing a book review?
My coworkers think I had a long honeymoon. Actually I was diagnosed with cancer. How do I talk about it?
What happened to all the nuclear material being smuggled after the fall of the USSR?
Importance sampling estimation of power function
Bent spoke design wheels — feasible?
On the Twin Paradox Again
Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?
Java guess the number
Sharing one invocation list between multiple events on the same object in C#
Finding row wise sum of transpose of hv-convex binary matrix
What can plausibly explain many of my very long and low-tech bridges?
Why is the relationship between frequency and pitch exponential?
Why don't B747s start takeoffs with full throttle?
Movie where a boy is transported into the future by an alien spaceship
You've spoiled/damaged the card
Is the decompression of compressed and encrypted data without decryption also theoretically impossible?
Is it a problem that pull requests are approved without any comments
What happens to foam insulation board after you pour concrete slab?
How would you say “AKA/as in”?
Removing applications from Show Applications without uninstalling
Return the Value of a function after aasy function ended
How do I return the response from an asynchronous call?Is there an “exists” function for jQuery?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueevent.preventDefault() vs. return falseWhy does ++[[]][+[]]+[+[]] return the string “10”?Copy array by valueHow do I return the response from an asynchronous call?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I try to wait for a function to return a value of my mysql table, and use this as a return for my const ProjektNameIntentHandler. This is my code:
const ProjektNameIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ProjektNameIntent';
,
handle(handlerInput)
let getProjektName = queryDb()
getProjektName.then(function(result)
var projektName = result[0];
console.log(projektName.Test);
)
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
Now the problem is that get the result of ProjektNameIntentHandler before projektName got the result. First, I tried to put the second return into the scope of the function. But in this way, the result also belongs to the funtion and not as a return for my ProjektNameIntentHandler.
So all I try do archieve is that the second return for the handlerinput, waits for my getProjektName.then to finish. How can I do that?
javascript node.js json alexa alexa-skills-kit
add a comment |
I try to wait for a function to return a value of my mysql table, and use this as a return for my const ProjektNameIntentHandler. This is my code:
const ProjektNameIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ProjektNameIntent';
,
handle(handlerInput)
let getProjektName = queryDb()
getProjektName.then(function(result)
var projektName = result[0];
console.log(projektName.Test);
)
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
Now the problem is that get the result of ProjektNameIntentHandler before projektName got the result. First, I tried to put the second return into the scope of the function. But in this way, the result also belongs to the funtion and not as a return for my ProjektNameIntentHandler.
So all I try do archieve is that the second return for the handlerinput, waits for my getProjektName.then to finish. How can I do that?
javascript node.js json alexa alexa-skills-kit
add a comment |
I try to wait for a function to return a value of my mysql table, and use this as a return for my const ProjektNameIntentHandler. This is my code:
const ProjektNameIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ProjektNameIntent';
,
handle(handlerInput)
let getProjektName = queryDb()
getProjektName.then(function(result)
var projektName = result[0];
console.log(projektName.Test);
)
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
Now the problem is that get the result of ProjektNameIntentHandler before projektName got the result. First, I tried to put the second return into the scope of the function. But in this way, the result also belongs to the funtion and not as a return for my ProjektNameIntentHandler.
So all I try do archieve is that the second return for the handlerinput, waits for my getProjektName.then to finish. How can I do that?
javascript node.js json alexa alexa-skills-kit
I try to wait for a function to return a value of my mysql table, and use this as a return for my const ProjektNameIntentHandler. This is my code:
const ProjektNameIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ProjektNameIntent';
,
handle(handlerInput)
let getProjektName = queryDb()
getProjektName.then(function(result)
var projektName = result[0];
console.log(projektName.Test);
)
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
Now the problem is that get the result of ProjektNameIntentHandler before projektName got the result. First, I tried to put the second return into the scope of the function. But in this way, the result also belongs to the funtion and not as a return for my ProjektNameIntentHandler.
So all I try do archieve is that the second return for the handlerinput, waits for my getProjektName.then to finish. How can I do that?
javascript node.js json alexa alexa-skills-kit
javascript node.js json alexa alexa-skills-kit
edited Mar 24 at 14:23
Nino Filiu
3,66241632
3,66241632
asked Mar 24 at 14:15
OlliOlli
83
83
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As you indeed guessed, as of now, you return undefined because the asynchronous function getProjektName has not yet resolved. The thing is, inside a synchronous function, you can't wait for a function to finish executing - you can only do that in asynchronous functions... However, you could make handle asynchronous! If that fits your requirements, you can modify your code as such:
const ProjektNameIntentHandler =
// ...
async handle(handlerInput) // 'async' makes the function asynchronous
let result = await queryDb(); // wait for the promise to resolve
let projektName = result[0];
console.log(projektName.Test);
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
I'll skip the lengthly explanations of how to embrace the asynchronicity of JavaScript - there's already a similar question with a high-quality answer that does just that!
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324712%2freturn-the-value-of-a-function-after-aasy-function-ended%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As you indeed guessed, as of now, you return undefined because the asynchronous function getProjektName has not yet resolved. The thing is, inside a synchronous function, you can't wait for a function to finish executing - you can only do that in asynchronous functions... However, you could make handle asynchronous! If that fits your requirements, you can modify your code as such:
const ProjektNameIntentHandler =
// ...
async handle(handlerInput) // 'async' makes the function asynchronous
let result = await queryDb(); // wait for the promise to resolve
let projektName = result[0];
console.log(projektName.Test);
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
I'll skip the lengthly explanations of how to embrace the asynchronicity of JavaScript - there's already a similar question with a high-quality answer that does just that!
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
add a comment |
As you indeed guessed, as of now, you return undefined because the asynchronous function getProjektName has not yet resolved. The thing is, inside a synchronous function, you can't wait for a function to finish executing - you can only do that in asynchronous functions... However, you could make handle asynchronous! If that fits your requirements, you can modify your code as such:
const ProjektNameIntentHandler =
// ...
async handle(handlerInput) // 'async' makes the function asynchronous
let result = await queryDb(); // wait for the promise to resolve
let projektName = result[0];
console.log(projektName.Test);
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
I'll skip the lengthly explanations of how to embrace the asynchronicity of JavaScript - there's already a similar question with a high-quality answer that does just that!
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
add a comment |
As you indeed guessed, as of now, you return undefined because the asynchronous function getProjektName has not yet resolved. The thing is, inside a synchronous function, you can't wait for a function to finish executing - you can only do that in asynchronous functions... However, you could make handle asynchronous! If that fits your requirements, you can modify your code as such:
const ProjektNameIntentHandler =
// ...
async handle(handlerInput) // 'async' makes the function asynchronous
let result = await queryDb(); // wait for the promise to resolve
let projektName = result[0];
console.log(projektName.Test);
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
I'll skip the lengthly explanations of how to embrace the asynchronicity of JavaScript - there's already a similar question with a high-quality answer that does just that!
As you indeed guessed, as of now, you return undefined because the asynchronous function getProjektName has not yet resolved. The thing is, inside a synchronous function, you can't wait for a function to finish executing - you can only do that in asynchronous functions... However, you could make handle asynchronous! If that fits your requirements, you can modify your code as such:
const ProjektNameIntentHandler =
// ...
async handle(handlerInput) // 'async' makes the function asynchronous
let result = await queryDb(); // wait for the promise to resolve
let projektName = result[0];
console.log(projektName.Test);
return handlerInput.responseBuilder
.speak(projektName.Test)
.withSimpleCard('Venture', projektName.Test)
.getResponse();
;
I'll skip the lengthly explanations of how to embrace the asynchronicity of JavaScript - there's already a similar question with a high-quality answer that does just that!
answered Mar 24 at 14:37
Nino FiliuNino Filiu
3,66241632
3,66241632
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
add a comment |
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
OMG IT FINALLY WORKS! Thank you so so much! I was brachiate through soooo many different methods and nothing worked. I cant beliefe it finaly came to an end!
– Olli
Mar 24 at 14:45
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
Great! I'm happy to hear that! By the way - it can feel weird for new users, but thank-you comments should be avoided, instead, simply upvote and/or accept the question - here's why. Happy coding @0lli1234!
– Nino Filiu
Mar 24 at 14:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324712%2freturn-the-value-of-a-function-after-aasy-function-ended%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown