freeman42x / haskell-editor-setup

Easy instructions for setting up Haskell editors / IDEs on any major operating system.
GNU General Public License v3.0
101 stars 15 forks source link

30m - Start `NW.JS` on HES run #96

Closed freeman42x closed 4 years ago

freeman42x commented 4 years ago

forkIO or Concurrently'd the nw . thing through the main process

alter2000 commented 4 years ago

The two options I know of thus far are:

  1. manually handle process and thread spawner (maybe just [callProcess]() at most)
    • allows most flexibility, have barely any idea how to achieve (maybe forkIO (Turtle.proc <nwjs)?)
  2. use concurrently to spawn both the NW.js and JSaddle process simultaneously
    • allows less flexibility, but things are still easy (we can set the second argument[1] to throw whenever nwjs has a nonzero exit code or some other weird case)

Chances are both will require extra dependencies, but:

  1. Turtle is already in use
  2. async is a well-known package and concurrently offers proper exception and other OS resource handling

So I'm not sure which one to pick.

[1]: concurrently :: IO a -> IO b -> IO (a, b)

freeman42x commented 4 years ago

@alter2000 Use Turtle please for spawning the processes in the correct order: main server and after that start NW.JS

freeman42x commented 4 years ago

So:

  1. Run the webserver
  2. When the webserver started run NW.JS in a blocking manner.
alter2000 commented 4 years ago

If we want to explicitly wait until the webserver is up, then we'll need to add an MVar to the mix to act as a binary semaphore. If we're doing that, we might as well use race which does that and the rest of the error handling for us. If what's needed is:

then this is a job for an MVar, since standard green threads (from forkIO and similar) can't be waited on or somehow joined until the whole process is shut down from main. This might not be an issue since everything starts and ends in main either way.

Related: we have to spawn a new thread before calling either blocking action (Turtle.proc or JSaddle.run), then spawn the blocking action itself. Since we can't wait without a semaphore, I decided to spawn the new thread, then run NWJS.

freeman42x commented 4 years ago

@alter2000 I trust you to make the best choice on this matter 💖