Starts a pool of workers that communicate with an external script via JSON over STDIN/STDOUT.
Originally written to use react-stdio but can be used with any process that reads a JSON object from STDIN and outputs JSON on STDOUT.
If available in Hex, the package can be installed as:
Add
std_json_ioto your list of dependencies inmix.exs:def deps do [{:std_json_io, "~> 0.1.0"}] end
Ensure
std_json_iois started before your application:def application do [applications: [:std_json_io]] end
Define a module and use StdJsonIo.
defmoduleMyApp.ReactIodouseStdJsonIo,otp_app: :my_appendWhen you use StdJsonIo your module becomes a supervisor. You'll need to add it
to your supervision tree.
children=[# snipsupervisor(MyApp.ReactIo,[])]opts=[strategy: :one_for_one,name: MyApp]Supervisor.start_link(children,opts)You can either configure as additional arguments of the use statement, or in your config file.
config:my_app,MyApp.ReactIo,pool_size: 20,# default 5max_overflow: 10,# default 10script: "path/to/script",# for react-io use "react-stdio"watch_files: [Path.join([__DIR__,"../priv/server/js/component.js"])# do not watch files in dev]script- the script to run for the IO serverwatch_files- A list of files to watch for changes. When the file changes, kill the IO worker and restart, picking up any changes. Use only in dev.pool_size- The size for the pool of workers - See poolboysizemax_overflow- The poolboymax_overflow