Package Exports
- @open-draft/until
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@open-draft/until) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
until
Gracefully handle a Promise using async/await.
Getting started
Install
npm install @open-draft/until
Use
import { until } from '@open-draft/until'
async function(id) {
const [error, user] = await until(() => fetchUser(id))
if (error) {
return handleError(error)
}
return user
}
Usage with TypeScript
import { until } from '@open-draft/until'
interface User {
firstName: string
age: number
}
interface UserFetchError {
type: 'FORBIDDEN' | 'NOT_FOUND'
message?: string
}
async function(id: string) {
const [error, user] = await until<User, UserFetchError>(() => fetchUser(id))
if (error) {
handleError(error.type, error.message)
}
return user.firstName
}