Ports in Elm

I recently finished the basic Elm tutorial that Tenor introduced me to. The last assignment was on ports.   This to me seemed very strange. What is an elm port?  Why do we need it? It reminded me of this this Rust WASM feature request:

Request for library: mpsc channels library built on top of the postMessage API #163

This could allow wasm to talk to js via CSP style message passing, different wasm instances to talk to each other without sharing memory, the wasm instances might even be in different threads by using web workers.

So what are Elm ports? Ports are the way that javascript and Elm talk to each other.  In Elm ports, messages are one way. It is not like http or tcp/ip where there is a handshake. I can send a message from JS to Elm, and vice versa, but I do not confirm that the message was received.

It is a pub/sub pattern, where JS subscribes to a port that is populated in Elm, and then sends messages on a port that is then handled in elm.

I did not expect Elm to work this way, but its not that strange. Maybe I can use some concepts and apply them to RUST WASM.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.