add a try sync to make working with results and promises easier#24
add a try sync to make working with results and promises easier#24CrowdHailer wants to merge 1 commit into
Conversation
|
The tests are an exact copy of the try_await tests with results not promise of results |
|
To come up with a contrived example think of a process where you want to chain result processing where some functions return promise or results but others just return results. For example getting a header and reading the body from a response. neglect for now differences in error type This won't work use header <- result.try(response.get_header(response, "x-header"))
use body <- promise.try_await(fetch.read_text_body(response))
... more functionProbably the simplest fix is use header <- promise.try_await(promise.resolve(response.get_header(response, "x-header")))
use body <- promise.try_await(fetch.read_text_body(response))
... more functionBut this creates a promise to immediately discard it in the call to try_await. and is noisy |
|
This is almost identical to Even if I were to modify |
I've ended up adding this to nearly every js project I create
The most recent use looks like this.