Skip to content

gen_server-based set of LFE/OTP Examples for running Ports in other languages

License

Notifications You must be signed in to change notification settings

lfeutre/port-examples

 
 

Repository files navigation

port-examples

Build Status LFE Versions Erlang Versions

An LFE/OTP application for running Port examples in various languages

Dependencies & Setup

This application assumes that the following are on your system:

  • git
  • GNU make
  • A modern install of Erlang (v20+)
  • rebar3 (Erlang build tool)
  • Golang
  • SBCL (Steel Bank Common Lisp)
  • Quicklisp

This project's rebar.config.script will set the required Go environment variables, but you will need to link the Common Lisp examples to your local Quicklisp directory:

cd apps/ports/priv/cl-ports-example/
ln -s `pwd` ~/quicklisp/local-projects/
cd -

Or you can run this convenience make target instead:

make quicklisp-link

Build & Run

make

This will build the Go and Common Lisp servers that are used in the examples, compile the LFE, and create an OTP release.

Now the app is ready to run:

make run

This will put you into a release console running the Erlang shell. Switch to LFE with the following:

1> lfe_shell:start().

See the running gen_servers for Go and CL:

lfe> (ports.app:children)
(#(ports.lisp.server #Pid<0.366.0> worker (ports.lisp.server))
 #(ports.go.server #Pid<0.365.0> worker (ports.go.server)))

Echo Examples

(ports.go.server:send #(command echo))
#(result "echo")
(ports.lisp.server:send #(command echo))
#(result "echo")

Crashing the Language Servers

You can induce a crash in the Go and Common Lisp echo servers. To easily see that a new port gets started up, let's take a look at the server PIDs and port IDs:

(ports@spacemac)lfe> (ports.app:servers)
(#(go #Pid<0.356.0>) #(lisp #Pid<0.357.0>))
(ports@spacemac)lfe> (ports.app:ports)
(#(go #Port<0.7>) #(lisp #Port<0.8>))

Now let's crash things:

(ports@spacemac)lfe> (ports.go.server:send #(command crash_it))
(ports@spacemac)lfe> (ports.lisp.server:send #(command crash_it))

Let's confirm that there are now new servers and ports created:

(ports@spacemac)lfe> (ports.app:servers)
(#(go #Pid<0.382.0>) #(lisp #Pid<0.385.0>))
(ports@spacemac)lfe> (ports.app:ports)
(#(go #Port<0.10>) #(lisp #Port<0.11>))

Releases

No releases published

Packages

No packages published

Languages

  • LFE 41.7%
  • Common Lisp 16.3%
  • Makefile 15.8%
  • Go 11.7%
  • Rust 10.0%
  • Erlang 4.5%