Fetcher icon indicating copy to clipboard operation
Fetcher copied to clipboard

call back? or using async await?

Open DeanKamali opened this issue 6 years ago • 0 comments

I'm trying to wait for refresh method to complete before proceeding with another task, in this example, I'm attempting to refresh datatable. after refresh 'profile' is finished.

            const update = async () => {
                await Fetcher.refresh("profile");
                console.log(Fetcher.get('profile').profile.family);
                this.$el.DataTable().clear().rows.add(Fetcher.get('profile').profile.family).draw();
            }
            update();

But it doesn't seem to work, any ideas?

update

I have also tried the following:

Set a temp key/value (loading: true} then run the refresh method, then write a setInterval function to check until that key is removed when data is refreshed, (I think it would be easier to provide a callback).

(Demo in chrome console)

let isLoading = setInterval(() => {
    if (!Fetcher.get('profile').hasOwnProperty('loading')) {
        this.$el.DataTable().clear().rows.add(Fetcher.get('profile').profile.family).draw();
        clearInterval(isLoading);
    }
}, 100);

Thanks

DeanKamali avatar May 20 '19 13:05 DeanKamali