Skip to content

yukikurage/reactive_signal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reactive_signal

A Gleam library for cross-process reactive signal

Warning

This is an experimental library, so breaking changes are actively made

Package Version Hex Docs

gleam add reactive_signal
import reactive_signal

pub fn main() {
  let new_listener = fn(logger) {
    fn(value) { process.send(logger, "Listened:" <> int.to_string(value)) }
  }

  let new_app = fn(logger: Subject(String)) {
    let #(sig, chn) = signal.new(0)
    let #(sig2, chn2) = signal.new(0)
    let sig3 = {
      use x <- signal.chain(sig)
      use y <- signal.chain(sig2)
      signal.pure(x + y)
    }
    signal.subscribe(sig3, new_listener(logger))
    channel.write(chn, 1)
    process.sleep(10)
    channel.write(chn2, 1)
    process.sleep(10)
  }

  let logger = process.new_subject()
  new_app(logger)

  process.receive(logger, 0)
  |> should.equal(Ok("Listened:0"))

  process.receive(logger, 0)
  |> should.equal(Ok("Listened:1"))

  process.receive(logger, 0)
  |> should.equal(Ok("Listened:2"))
}

Further documentation can be found at https://hexdocs.pm/reactive_signal.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages