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;








1















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?










share|improve this question






























    1















    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?










    share|improve this question


























      1












      1








      1








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 14:23









      Nino Filiu

      3,66241632




      3,66241632










      asked Mar 24 at 14:15









      OlliOlli

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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!






          share|improve this answer























          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          0














          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!






          share|improve this answer























          • 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















          0














          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!






          share|improve this answer























          • 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













          0












          0








          0







          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!






          share|improve this answer













          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!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해