Js_of_ocaml_eio.Eio_promiseConversions between JavaScript promises (Js_of_ocaml.Promise) and Eio fibers.
await ?abort p waits for the promise p to be settled and returns its value. Exception Rejected is raised if p is rejected. The optional abort function is called when the fiber is cancelled.
make ~sw fn runs fn in a new fiber (attached to sw) and returns a promise which is resolved with the return value of the function. If the function raises an exception, the promise is rejected and sw is not failed. The rejection reason is e for exception Rejected e, the JavaScript error e for exception Js.Js_error.Exn e, and Promise.error_of_exn exn for any other exception exn. If sw is already cancelled or finished, the function is not run and the promise is rejected with the exception returned by Eio.Switch.get_error.
Every exception is turned into a rejection, including Eio.Cancel.Cancelled (when sw is cancelled while fn runs) and exceptions such as Assert_failure that indicate a bug: they are not reported elsewhere, so they are lost if the rejection is not handled.
run fn runs fn in a new Eio context (Eio_js.start) and returns a promise of its result, rejected as with make if it raises. This is how JavaScript callbacks that must return a promise (e.g. request handlers) run Eio code: fn can use a Switch.run of its own. Unlike Eio_js.start, an exception raised by fn does not go to the uncaught exception handler.