haterapps / fake-data

Fake Data - A form filler you won't hate
39 stars 2 forks source link

Using await for customer generators #22

Closed SpuriousGer closed 2 years ago

SpuriousGer commented 2 years ago

I want to use a value from a previous generator, but it is an asnyc operation.

This one is not working for me:

const val = await fakeData.getLastGeneratedValue('asset_value');
return (Math.random() * val);

How can I get this implemented?

haterapps commented 2 years ago

Hello,

Using await directly is not yet supported, but you can return a Promise that contains an async function.

In other words, you can try this:

return new Promise(async function(resolve) {
    const val = await fakeData.getLastGeneratedValue('asset_value');
    resolve((Math.random() * val));
});
SpuriousGer commented 2 years ago

Awesome, thanks a lot