javascript-bridge-0.2.0: Remote Monad for JavaScript on the browser

Safe HaskellNone
LanguageHaskell2010

Network.JavaScript.Services

Contents

Synopsis

Web Services

data Engine Source #

An Engine is a handle to a specific JavaScript engine

Constructors

Engine 

start :: (Engine -> IO ()) -> Application -> Application Source #

This accepts WebSocket requests, calls the callback with an Engine that can be used to access JavaScript.

addListener :: Engine -> (Value -> IO ()) -> IO ThreadId Source #

Add a listener for events. There can be many. non-blocking.

From JavaScript, you can call event(..) to send values to this listener. Any valid JSON value can be sent.

listen :: Engine -> IO Value Source #

listen for the next event. blocking.

From JavaScript, you can call event(..) to send values to this listener. Any valid JSON value can be sent.

readEventChan :: Engine -> STM (Value, UTCTime) Source #

readEventChan uses STM to read the next event.

From JavaScript, you can call event(..) to send values to this channel. Any valid JSON value can be sent.

type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived #

The WAI application.

Note that, since WAI 3.0, this type is structured in continuation passing style to allow for proper safe resource handling. This was handled in the past via other means (e.g., ResourceT). As a demonstration:

app :: Application
app req respond = bracket_
    (putStrLn "Allocating scarce resource")
    (putStrLn "Cleaning up")
    (respond $ responseLBS status200 [] "Hello World")