A
A
asd dsa2019-12-24 19:38:58
JavaScript
asd dsa, 2019-12-24 19:38:58

How to extract values ​​from an async method into an object property?

I want to extract the value from the `extractZMockClient` asynchronous method and put this value in the properties: `defaultClient`, `clients` of the `apolloProvider` object.
I already do this but in the console I still get this:
5e023e86040b5780041092.jpeg

const ZMockClient = async () => import("z-mock-client")

const extractZMockClient = async () => {
    try {
        const callZMockClient = await ZMockClient()
        return callZMockClient.mockedClient
    } catch (ex) {
        throw new Error(ex)
    }
}

const apolloProvider = new VueApollo({
    defaultClient: MOCKED_UI ? extractZMockClient() : v2,
    clients: {
        v2: MOCKED_UI ? extractZMockClient() : v2
    }
})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2019-12-24
@abberati

There is NO way you can move a value from asynchronous code to synchronous code, because at the time of execution of the asynchronous code, all synchronous code has already been executed.
The only option is to execute asynchronously the code that is tied to other asynchronous code. That is, you need to create an apolloprover also asynchronously. Write a function that will return a promise with a provider and use it where necessary.

E
Evgeny Kulakov, 2019-12-24
@kulakoff Vue.js

... await extractZMockClient()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question