parvel / parvel_IO.ml

include IO_Lwt;

value ( >>= ) = bind_rev
;

value return_unit = return ()
;

module Mq
 :
  sig
    type t 'a;
    value create : unit -> t 'a;

    exception Full;

    value set_block_limit : t 'a -> int -> unit;
    value set_fail_limit : t 'a -> int -> unit;

    (* теперь это синонимы, и оно само блокируется, когда надо.
       может приведу потом до единого, но вдруг захочется
       обратно mvar или подобное. *)
    value put : t 'a -> 'a -> m unit;
    value put_blocking : t 'a -> 'a -> m unit;

    value take : t 'a -> m 'a;
    value idle_reader_exists : t 'a -> bool;
  end
 =
  struct
    open Lwt_mq_parvel;
    type t 'a = Lwt_mq_parvel.t 'a;
    value create = Lwt_mq_parvel.create;

    exception Full;

    value full_error = error Full;

    value put q v =
     bind_rev
     (Lwt_mq_parvel.put q v)
     (fun
      [ True -> return_unit
      | False -> full_error
      ])
    ;

    value put_blocking = put;

    value take = take;
    value idle_reader_exists = have_any_reader;

    value set_block_limit = Lwt_mq_parvel.set_block_limit;
    value set_fail_limit = Lwt_mq_parvel.set_fail_limit;

  end
;


value run_and_ignore_result : m unit -> unit = Lwt.ignore_result;
value join : list (m unit) -> m unit = Lwt.join;

value fprintf outch fmt = Printf.ksprintf (fun s -> write outch s) fmt;

(*
value printf fmt = fprintf stdout fmt;
*)

value printf fmt = Printf.ksprintf (fun s -> write stdout s) fmt;


(* временно, будет меняться: *)
type sink 'a = Lwt.u 'a  (* по идее эта срань должна быть контрвариантной *)
 and source +'a = Lwt.t 'a
;

value pipe1 : unit -> (source 'a * sink 'a) = Lwt.wait
  and put_sink : sink 'a -> 'a -> unit = Lwt.wakeup
  and wait_source : source 'a -> m 'a = fun s -> s
;

value sleep = Lwt_unix.sleep
;


open Cd_All; open Cdt;

class ti ['z] (ti_a : Cdt.ti 'a) () =
  ti_simple ['z] (Printf.sprintf "Lwt.t (%s)" ti_a#type_name)
;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.