Giter Club home page Giter Club logo

dp-system-process's Introduction

WARNING! This is a work in progress, and it is still experimental, use it at your own risk

dp-system-process

This library allows the creation of system processes using the distributed-process Actor's library.

Installation and usage

This library requires using cabal sandbox with the following sub-projects (mind the 'development' branch part):

In order to run tests, you'll also need network-transport-inmemory

There is a Makefile that would facilitate running the test suite, just do make test.

Documentation

Currently you can read the documentation by doing cabal haddock and accessing it through dist/doc folder

Example

The API tries to replicate as much as it can from System.Process, there are bits that change specifically on the std_out and std_err. There is also a new exit_code field.

You may send ByteStrings to the process std_in by using the writeStdin function.

An example to better explain how it works:

import Control.Monad (forever)
import Control.Monad.Trans (liftIO)

import Control.Concurrent (threadDelay)

import Network.Transport.Chan (createTransport)
import Control.Distributed.Process.Node (runProcess, newLocalNode, initRemoteTable)
import qualified Control.Distributed.Process as Process

import Control.Distributed.Process.SystemProcess as Proc

main :: IO ()
main = do
  -- Cloud Haskell boilerplate
  transport <- createTransport
  node <- newLocalNode transport initRemoteTable
  runProcess node $ do

    -- Actual example

    -- Listener is going to receive stdout and exit code from the system process actor
    listenerPid <- Process.spawnLocal $ do
      forever $
        Process.receiveWait [ Process.matchIf Proc.isExitCode (liftIO . print)
                            , Process.matchIf Proc.isStdOut (liftIO . print) ]

    -- current actor is going to become the process actor
    Proc.runSystemProcess
      -- Process.send std_out and exit_code to listenerPid
      -- There are different transports, check the haddock documentation
      (Proc.proc "ls" ["-l", "-a"]) { Proc.std_out = Proc.sendToPid listenerPid
                                    , Proc.exit_code = Proc.sendToPid listenerPid }

    liftIO $ threadDelay 10000
    Process.kill listenerPid "time to die..."

dp-system-process's People

Contributors

roman avatar

Watchers

Tavis Rudd avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.