sanctuary-def
sanctuary-def copied to clipboard
Async Type Checking
I propose we support a new function defAsync that merely states the result is an asynchronous value (we could parameterize what an async result looks like).
Why?
If the user can tell sanctuary-def that a function is async, it could open up this library to moving type checking to a worker thread (in the browser), or a child process (in node). It gives sanctuary-def permission to do exhaustive checks on recursive types or complex constraints without blowing the stack, simply by recurring asynchronously.
If we can move type checking off the main thread, we could keep type checking on in production without experiencing jank in the UI.
We'd also potentially allow sanctuary-def to give us better verification of async results, by allowing sanctuary-def to traverse async results when they eventually arrive.
I'd be happy to tinker with this on another branch if it seems like something we may want. Even if doesn't work out, it could be an interesting experiment.
This is an interesting idea. Please tinker. :)
An alternative to having a new definition function would be to annotate a type w/ an async flag. Then if a checked function has a return type that is async, Sanctuary could do its webworker magic.