Snippets

orbitzN Eventually consistent replicated state machine

Created by orbitzN last modified
open Async.Std

module Next : sig
  type 'a t =
    | Next of 'a
    | End
end

(*
 * This represents a snapshot which is used to synchronize.
 * Snapshots are immutable and all synchornization returns
 * a list of operations to apply to the state machine.
 *)
module type S = sig
  type t
  type cont
  type chunk
  type op

  (*
   * Create a starting point to synchrnoize.
   *)
  val start : t -> cont Deferred.t

  (*
   * Take the current position in synchronization and give
   * back a chunk to synchronize and the next step in the
   * synchronization.
   *)
  val next : cont -> t -> (chunk * cont) Next.t Deferred.t

  (*
   * sync takes a synchronization chunk and gives back
   * a list of operations to apply locally as well as an
   * optional chunk to send to the other node involved
   * in the sync to apply.  If there is no chunk given back
   * it means the two nodes are synced.
   *)
  val sync : chunk -> t -> (op list * chunk option) Deferred.t
end
open Async.Std

module type S = sig
  type t
  type op
  type ret
  type snapshot

  val apply : t -> op -> ret Deferred.t

  (*
   * This will return when the state machine is able to
   * accept operations again.
   *)
  val snapshot : t -> snapshot Deferred.t
end

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.