ghcjs / jsaddle

JavaScript interface that works with GHCJS or GHC
116 stars 62 forks source link

How to get result of promise/async function without a continuation Haskell function. #116

Open rowanG077 opened 4 years ago

rowanG077 commented 4 years ago

I have started using Miso with GHCJS and I want to use the web usb API to talk to some local embedded device. I can do this fine by creating foreign functions in GHCJS with something like this:

foreign import javascript interruptible
  "navigator.usb.requestDevice({ filters: [ $1 ]}).then($c);"
  jsRequestUSBDeviceAccess :: JsObj.Object -> IO JsObj.Object

Now I can simply call the function in Haskell like this:

usbDev <- jsRequestUSBDeviceAccess filters

Since I want to move to jsaddle I want to know how I can essentially rewrite this structure to be compatible with jsaddle. I in particular don't want two function where the second function is a continuation.