Async
Abstraction for async operations that can be hooked into React.
Source code is hosted in GitHub
yarn add @corets/asyncnpm install --save @corets/asyncSeamless React integrations are shipped inside separate packages:
useAsyncuseStreamuseActioncreateAsync()
Create an observable async operation:
import { createAsync } from "@corets/async"
const query = createAsync(async () => "some data")Create an observable async operation without the factory function:
import { Async } from "@corets/async"
const query = new Async(async () => "some data")Async.getResult()
Retrieve result from the last invocation:
Async.getError()
Retrieve probable error from the last invocation:
Async.getState()
Retrieve all the details in a single call, contains values like isRunning, isCancelled, result, etc.:
Async.isRunning()
Check if the async operation is being executed right now:
Async.isCancelled()
Check if the latest async invocation has been cancelled:
Async.isErrored()
Check if the latest async invocation errored:
Async.run()
Invoke async operation:
Async.resolve()
Manually resolve async result, makes it available on the instance using getResult():
Async.cancel()
Cancel current async invocation:
Async.listen()
Subscribe to state changes, the listener receives the same object that you get from getState():
Last updated
Was this helpful?