Comment

Comment by tophercyll

Ignoring user interface and the mechanics of peer discovery...

  user-interface, discovery-system |
  # This process is spawned with two pids as arguments
  
  # If either pid halts, I halt too.
  user-interface.link
  discovery-system.link
  
  user-interface.subscribe(when(
    text-entered: { message |
      # I entered a message in the UI, announce it to everyone subscribed to me
      my-actor.announce('exclaimed, message)
    }
  ))
  
  discovery-system.subscribe(when(
    peer-discovered: { name, peer |
      # Discovery system located another user in the chat room
  
      # Send message to user-interface showing a Growl style notification.
      user-interface << ('notify, "{name} arrived.")
  
      peer.subscribe(when(
        # This guy went away - "halted" is announced when a process stops
        halted: { result | user-interface << ('notify, "{name} left.") }
  
        # This guy said something
        exclaimed: { message | user-interface << ('text-append, "{name}: {message}") }
      ))
    }
  )
  
  main.loop
parent tophercyll 16 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton