on develop help sign in
implement asynchronus websocket initialization
commitd3e034690b768654b1115d2c6f21ffa0c5d7312b authorhsloan <ishaqsloan@gmail.com> dateWed 19 Dec 2018, 15:27 (8 years ago) parent8150c0a
1 file changed+6−1
reflex-dom-core/src/Reflex/Dom/WebSocket.hs+6−1
reflex-dom-core/src/Reflex/Dom/WebSocket.hs+6−1
@@ -102,7 +102,7 @@ webSocket' url config onRawMessage = do
102102 liftIO $ triggerEClose args
103103 _ <- liftIO $ atomically $ tryTakeTMVar isOpen
104104 liftIO $ writeIORef currentSocketRef Nothing
105− when (_webSocketConfig_reconnect config) $ do
105+ when (_webSocketConfig_reconnect config) $ forkJSM $ do
106106 liftIO $ threadDelay 1000000
107107 start
108108 start = do
@@ -144,6 +144,11 @@ jsonWebSocket url cfg = do
144144 ws <- textWebSocket url $ cfg { _webSocketConfig_send = fmap (decodeUtf8 . toStrict . encode) <$> _webSocketConfig_send cfg }
145145 return ws { _webSocket_recv = jsonDecode . textToJSString <$> _webSocket_recv ws }
146146
147+forkJSM :: JSM () -> JSM ()
148+forkJSM a = do
149+ jsm <- askJSM
150+ void $ liftIO $ forkIO $ runJSM a jsm
151+
147152#ifdef USE_TEMPLATE_HASKELL
148153makeLensesWith (lensRules & simpleLenses .~ True) ''WebSocketConfig
149154makeLensesWith (lensRules & simpleLenses .~ True) ''RawWebSocket