package bonsai

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file global_state.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
open! Core
open! Async
open Bonsai_chat_open_source_common

type t =
  { message_bus : (Message.t -> unit) Bus.Read_write.t
  ; messages : Message.t Queue.t Room.Table.t
  }

let create () =
  let message_bus =
    Bus.create
      [%here]
      Arity1
      ~on_subscription_after_first_write:Allow
      ~on_callback_raise:(fun error -> print_s [%sexp (error : Error.t)])
  in
  let initial_messages =
    [ Message.
        { room = Room.of_string "incr_dom-room"
        ; author = "Bonsai Developers"
        ; contents = "hello world!"
        }
    ; Message.
        { room = Room.of_string "incr_dom-room"
        ; author = "Bonsai Developers"
        ; contents =
            "For deep and complex security purposes your messages will be hashed so that \
             you can't use this platform for actual chatting"
        }
    ]
  in
  let messages =
    Room.Table.of_alist_exn
      [ Room.of_string "incr_dom-room", Queue.of_list initial_messages
      ; Room.of_string "bonsai-room", Queue.of_list initial_messages
      ]
  in
  { message_bus; messages }
;;
OCaml

Innovation. Community. Security.