2.2.0
New Features
- support for wrapping an asynchronous function
Before if we want to wrap an async value, we need to get the promise value first, then pass it to the wrap
function, like this
const v = Promise.resolve(1)
wrap(v).unwrap()
But this is not that convenient if we want to just wrap an async function so that others can use it without the need to wrap it explicitly. Not the wrap
function accepts async function.
import {wrap} from 'unwrapit'
const fetchWrapper = wrap(fetch)
const ret = (await fetchWrapper('www.google.com')).unwrap()
const json = await ret.json())
Now you can share a wrapped async function with others, and it will be wrapped with Result types naturally.