Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useAsyncState): add support directly await #3004

Merged
merged 3 commits into from Apr 22, 2023

Conversation

Hfutsora
Copy link
Contributor

Add initialized in the useAsyncState.

Description

Sometimes, using only isReady or isLoading is not very convenient.

For example, in scenarios where multiple events rely on state being triggered, and the execute may not have been completed yet.

We need to use await initialized to ensure that subsequent operations are executed only after the state has been initialized.

Example

<script lang="ts" setup>
const { initialized, state } = useAsyncState(p1, 0, { immediate: true })

const eventA = async () => {
  await initialized.value
  // do something with the state...
}
const eventB = async () => {
  await initialized.value
  // do something with the state ...
}
</script>

@antfu
Copy link
Member

antfu commented Apr 20, 2023

I think instead, we could return a then method to proactively wait for current promises. You could refer to useFetch

@Hfutsora Hfutsora force-pushed the feat(useAsyncState)--add-initialized branch from 47c1829 to 2851571 Compare April 21, 2023 03:59
@Hfutsora
Copy link
Contributor Author

Thank you for your suggestion. I have modified the original design to return a thenable object.

@antfu antfu changed the title feat(useAsyncState): add initialized feat(useAsyncState): add support directly await Apr 21, 2023
@antfu antfu merged commit d4db0ad into vueuse:main Apr 22, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants