-
The JS FFI documentation has this example: foreign import javascript unsafe "new Date()" current_time :: IO JSVal but lets say I write my own date function: foreign import javascript unsafe "myDate()" current_time :: IO JSVal Where do I have to put |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, it is! I use the Haskell code: foreign import javascript unsafe "sendMessage" sendMessage' :: JSVal -> IO ()
foreign import javascript safe "requestMessage" requestMessage' :: JSVal -> IO JSVal
sendMessage :: ToJSON a => a -> IO ()
sendMessage = sendMessage' . jsonToJSVal
requestMessage :: (ToJSON a, FromJSON b) => a -> IO (Maybe b)
requestMessage m = do
msg <- requestMessage' $ jsonToJSVal m
case jsonFromJSVal msg of
Right r -> pure $ Just r
Left _ -> pure Nothing and modify the var closure = null;
onmessage = function(msg) {
if(closure !== null) {
var cl = closure
closure = null;
cl(msg.data);
} else {
console.log("Unhandled by Worker: ");
console.log(msg.data);
}
};
var requestMessage = function(msg) {
postMessage(msg);
return new Promise((resolve, reject) => {
closure = resolve;
});
};
var sendMessage = function(msg) {
postMessage(msg);
};
export default ... __asterius_jsffi_async_mainzuMain_ajch:($1)=>__asterius_jsffi.returnFFIPromise((async () => {$1 = __asterius_jsffi.getJSValzh($1);return [1, await (requestMessage($1))];})()),__asterius_jsffi_mainzuMain_ajqL:($1)=>{$1 = __asterius_jsffi.getJSValzh($1);return (sendMessage($1));}}}) ... This means that I can't use the |
Beta Was this translation helpful? Give feedback.
Yes, it is!
I use the Haskell code:
and modify the
<project>.req.mjs
file to be: