<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Custom Visual await Promise in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632282#M1824</link>
    <description>&lt;P&gt;private storage: ILocalVisualStorageService -&amp;gt; API which returns storage info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem is, that thread is not waiting for promise result, it moves on. Here is the example code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/149011i0F5C63534D127C55/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Feb 2019 18:19:09 GMT</pubDate>
    <dc:creator>mikihiir</dc:creator>
    <dc:date>2019-02-26T18:19:09Z</dc:date>
    <item>
      <title>Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/630433#M1812</link>
      <description>&lt;P&gt;Hei&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone tried to await for Promise ?&lt;/P&gt;&lt;P&gt;Seems that thread is not blocked&amp;nbsp; until Promise&amp;nbsp; returns the answer. it just runs on.&lt;/P&gt;&lt;P&gt;Async is working perfectly but when using await for syncronous then not working ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code example -&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 488px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/148510iEB98B29853DAE48B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance !&lt;/P&gt;</description>
      <pubDate>Sun, 24 Feb 2019 18:21:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/630433#M1812</guid>
      <dc:creator>mikihiir</dc:creator>
      <dc:date>2019-02-24T18:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/631792#M1820</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aync will not work for synchronous code because it is syntax error&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 435px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/148869iD25113DB32C7A65C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Why thread must be blocked?&lt;/P&gt;&lt;P&gt;You called async function as sync and it creates a Promise that is async but in fact will be called immediatelly, but you called setTimeout inside that is asynchronous too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Evgenii Elkin,&lt;/P&gt;&lt;P&gt;Software Engineer&lt;/P&gt;&lt;P&gt;Microsoft Power BI Custom Visuals&lt;BR /&gt;pbicvsupport@microsoft.com&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:35:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/631792#M1820</guid>
      <dc:creator>v-evelk</dc:creator>
      <dc:date>2019-02-26T08:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632277#M1823</link>
      <description>&lt;P&gt;I want the thread to wait until promise return the result&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 17:55:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632277#M1823</guid>
      <dc:creator>mikihiir</dc:creator>
      <dc:date>2019-02-26T17:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632282#M1824</link>
      <description>&lt;P&gt;private storage: ILocalVisualStorageService -&amp;gt; API which returns storage info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem is, that thread is not waiting for promise result, it moves on. Here is the example code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/149011i0F5C63534D127C55/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 18:19:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632282#M1824</guid>
      <dc:creator>mikihiir</dc:creator>
      <dc:date>2019-02-26T18:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632807#M1826</link>
      <description>&lt;P&gt;It is how async functions work on the top level. They will wait for results only in their chain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there are 2 solutions that may solve your question:&lt;/P&gt;&lt;P&gt;1. You can wrap your code in a promise on the top level.&lt;/P&gt;&lt;P&gt;2. You can wrap your code in an immediate async function like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(async () =&amp;gt; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp;try {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; debugger;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; await this.getData();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; debugger;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;} catch (e) {}&lt;BR /&gt;})();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Evgenii Elkin,&lt;BR /&gt;Software Engineer&lt;BR /&gt;Microsoft Power BI Custom Visuals&lt;BR /&gt;pbicvsupport@microsoft.com&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 08:10:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/632807#M1826</guid>
      <dc:creator>v-evelk</dc:creator>
      <dc:date>2019-02-27T08:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/633493#M1835</link>
      <description>&lt;P&gt;Thanks for replying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tho option 2. is not helping,&amp;nbsp; code is still not waiting for promise. Can u make an example of option 1 (&lt;SPAN&gt;code in a promise on the top level&lt;/SPAN&gt;) ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 20:56:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/633493#M1835</guid>
      <dc:creator>mikihiir</dc:creator>
      <dc:date>2019-02-27T20:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/634254#M1841</link>
      <description>&lt;P&gt;The second approach must work because it is regular JS behavior. PowerBi Custom Visual code cannot work other way than regular JS flow.&lt;/P&gt;&lt;P&gt;I suppose that you probably put your code in a wrong place.&lt;/P&gt;&lt;P&gt;I attached an example of the code that outputs the messages in the next order:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Async function was started"&lt;/P&gt;&lt;P&gt;"Set Timeout"&lt;/P&gt;&lt;P&gt;"Promise result was gotten"&lt;/P&gt;&lt;P&gt;"Some code after async call!"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;script&amp;gt;
function getPosts() {
   return new Promise((resolve, redject) =&amp;gt; {
      setTimeout(() =&amp;gt; {
         console.log("Set Timeout");
         resolve(1);
      }, 2000);
   });
}

async function init() {
   console.log("Async function was started");
   await getPosts().then((result) =&amp;gt; { console.log("Promise result was gotten") });
}


(async () =&amp;gt; {
    try {
        var text = await init();
        console.log("Some code after async call!");
        // other code that must wait for async result must be located here
    } catch (e) {
    }
})();
&amp;lt;/script&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Evgenii Elkin,&lt;BR /&gt;Software Engineer&lt;BR /&gt;Microsoft Power BI Custom Visuals&lt;BR /&gt;pbicvsupport@microsoft.com&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 13:14:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/634254#M1841</guid>
      <dc:creator>v-evelk</dc:creator>
      <dc:date>2019-02-28T13:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/940588#M3000</link>
      <description>&lt;P&gt;I for one, still can't get this to work&lt;/P&gt;&lt;P&gt;I have created a new post (&lt;A href="https://community.powerbi.com/t5/Custom-Visuals-Development/Can-t-get-async-wait-to-work-in-any-form-or-shape-within-a/m-p/936229#M2991" target="_blank"&gt;https://community.powerbi.com/t5/Custom-Visuals-Development/Can-t-get-async-wait-to-work-in-any-form-or-shape-within-a/m-p/936229#M2991&lt;/A&gt;) enquiring about this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking that either I am not pointing my custom viz correctly to esnext or I am putting the async logic in the wrong place...&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 10:52:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/940588#M3000</guid>
      <dc:creator>Schizzomarino</dc:creator>
      <dc:date>2020-02-20T10:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual await Promise</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/941511#M3002</link>
      <description>&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Custom-Visuals-Development/Can-t-get-async-wait-to-work-in-any-form-or-shape-within-a/m-p/941499/highlight/true#M3001" target="_self"&gt;Hopefully this post&lt;/A&gt; will clarify for SDK v3.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 20:49:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Custom-Visual-await-Promise/m-p/941511#M3002</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2020-02-20T20:49:17Z</dc:date>
    </item>
  </channel>
</rss>

