0

I have been playing with purescript and signals. I have a block of code

runSignal $ (every 2000.0) ~> logShow

which when compiled into a JS file(pulp browserify) as

main = do 
         runSignal $ (every 2000.0) ~> logShow

and executed on the browser, works as expected(logs something every 2 seconds), but gets stuck on the psci console. Why is this behaviour? Any help would be appreciated.

2 Answers2

0

PSCi has two modes:

  • It can use Node for execution of compiled JS (the default mode). In this mode, it starts a new Node process for each expression, and prints the result synchronously in the console.
  • It can use a web browser for execution (using the --port option) via a websocket. In this mode, it sends a snippet of JS to a long-running browser process.

In the first mode, runSignal isn't going to do anything interesting, since it will start a timer and return immediately, but you can probably get something working easily using the second mode.

Phil Freeman
  • 4,199
  • 1
  • 20
  • 15
  • Thanks Phil. But the next psci prompt isn't even shown on running this line. It get's stuck and I have to do a ^C to interrupt it. Is this the result of synchronous running of the node process which keeps waiting for the result of this expression? – Paul Victor Raj Feb 24 '17 at 05:40
0

I've seen similar behavior with neverending processes in psci. A simple example would be...

module NeverEnding where

import Prelude
import Control.Monad.Eff.Console (log)
import Control.Monad.Rec.Class (forever)

main = forever $ do
  log "log"

If you load this module in psci and run main, you won't see any output. From a workflow perspective, if you want to test something like this from the console, I suggest running pulp --watch run --main NeverEnding. --main will set the module that you want as the main entrypoint. --watch will watch for file changes, and on change, kill the neverending process, recompile, and restart.

Albtzrly
  • 924
  • 1
  • 6
  • 15