Skip to content

Commit

Permalink
Always have a polling module
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg committed Nov 7, 2019
1 parent 0bfdada commit 76e2bdf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 77 deletions.
41 changes: 1 addition & 40 deletions src/backend.polling.ml
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)

open Lwt.Infix

let src = Logs.Src.create "irw-polling" ~doc:"Irmin watcher using using polling"
module Log = (val Logs.src_log src : Logs.LOG)

let with_delay delay =
Log.info (fun l -> l "Polling mode");
let wait_for_changes () = Lwt_unix.sleep delay >|= fun () -> `Unknown in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)

let mode = `Polling

let v =
Log.info (fun l -> l "Polling mode");
let wait_for_changes () =
Lwt_unix.sleep !Core.default_polling_time >|= fun () -> `Unknown
in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)

(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*)
include Polling
38 changes: 1 addition & 37 deletions src/backend.polling.mli
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)

(** Active polling backend for Irmin watchers.
{e %%VERSION%% — {{:%%PKG_HOMEPAGE%% }homepage}} *)

open Core

val with_delay: float -> t
(** [with_delay delay id p f] is the hook calling [f] everytime a
sub-path of [p] is modified. Return a function to call to remove
the hook. Active polling is done every [delay] seconds. *)

val v: t
(** [v] is [with_delay !default_polling_time]. *)

val mode: [`Polling]

(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*)
include module type of struct include Polling end
40 changes: 40 additions & 0 deletions src/polling.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)

open Lwt.Infix

let src = Logs.Src.create "irw-polling" ~doc:"Irmin watcher using using polling"
module Log = (val Logs.src_log src : Logs.LOG)

let with_delay delay =
Log.info (fun l -> l "Polling mode");
let wait_for_changes () = Lwt_unix.sleep delay >|= fun () -> `Unknown in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)

let mode = `Polling

let v =
Log.info (fun l -> l "Polling mode");
let wait_for_changes () =
Lwt_unix.sleep !Core.default_polling_time >|= fun () -> `Unknown
in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)

(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*)
37 changes: 37 additions & 0 deletions src/polling.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)

(** Active polling backend for Irmin watchers.
{e %%VERSION%% — {{:%%PKG_HOMEPAGE%% }homepage}} *)

open Core

val with_delay: float -> t
(** [with_delay delay id p f] is the hook calling [f] everytime a
sub-path of [p] is modified. Return a function to call to remove
the hook. Active polling is done every [delay] seconds. *)

val v: t
(** [v] is [with_delay !default_polling_time]. *)

val mode: [`Polling]

(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*)

0 comments on commit 76e2bdf

Please sign in to comment.