Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Schizzomarino
Helper I
Helper I

Can't get async / wait to work in any form or shape within a custom viz

I am trying to animate a chart in subsequent steps in a custom visualisation but I could not get it to work, eventually I'd like to use await the promise from d3.transition.end() (d3 v5.7 with correct typing); but right now I'd be very happy to just see sync/await work in a Power BI

I have simplified the async call here to test and share (from a similar post here in the Power BI community ) I get no logs at all from the below), can anyone please tell me what I am doing wrong?

 

public update(optionsVisualUpdateOptions) {

        function getPosts() {
            return new Promise((resolvereject=> {
                setTimeout(() => {
                    console.log("Set Timeout");
                    resolve(1);
                }, 20);
            });
            } 
        async function init() { 
            console.log("Async function was started");
            await getPosts().then((result=> { console.log("Promise result received") });
        }
        
       (async () => {
            try {
                var text = await init();
                console.log("Some code after async call!");
            } catch (e) {}
        })();
}
 
 
 
Am I missing a library or something, should this not go in the Update function?
I have done research but I can't seem to find a solution.
I am using pbiviz 3.1.5

 
Thanks for any help you may provide,
 
Daniel
1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @Schizzomarino,

Your code is definitely okay. Your issue appears to be with Webpack and no further configuration is required from creating a new visual other than ensuring that you have regenerator-runtime as a dependent package and referenced in your visual.ts.

I've made a simple Git repo that you can clone and take a look at if you want to validate or see any differences to your code, and I'll link the sections of code as prescribed. Essentially, you just need to do the following:

I now get the following in my console with your code:

image.png

Hopefully this gets you moving though. Good luck!

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

3 REPLIES 3
luojiandan_bi
Helper I
Helper I

It's great!I got the same error ago,but worked now.

thanks so much for @dm-p 

dm-p
Super User
Super User

Hi @Schizzomarino,

Your code is definitely okay. Your issue appears to be with Webpack and no further configuration is required from creating a new visual other than ensuring that you have regenerator-runtime as a dependent package and referenced in your visual.ts.

I've made a simple Git repo that you can clone and take a look at if you want to validate or see any differences to your code, and I'll link the sections of code as prescribed. Essentially, you just need to do the following:

I now get the following in my console with your code:

image.png

Hopefully this gets you moving though. Good luck!

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Oh wow, thanks so much for this Daniel!

Worked like a charm!

 

Now to start using generator functions right? 😄

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors