From 76e2bdf929c55890f575e0a9ed50aabac706527d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 8 Nov 2019 00:17:36 +0900 Subject: [PATCH] Always have a polling module Signed-off-by: Rudi Grinberg --- src/backend.polling.ml | 41 +---------------------------------------- src/backend.polling.mli | 38 +------------------------------------- src/polling.ml | 40 ++++++++++++++++++++++++++++++++++++++++ src/polling.mli | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 77 deletions(-) create mode 100644 src/polling.ml create mode 100644 src/polling.mli diff --git a/src/backend.polling.ml b/src/backend.polling.ml index 6c0be95..3f52be8 100644 --- a/src/backend.polling.ml +++ b/src/backend.polling.ml @@ -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 diff --git a/src/backend.polling.mli b/src/backend.polling.mli index e61ed19..09b9a35 100644 --- a/src/backend.polling.mli +++ b/src/backend.polling.mli @@ -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 diff --git a/src/polling.ml b/src/polling.ml new file mode 100644 index 0000000..6c0be95 --- /dev/null +++ b/src/polling.ml @@ -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. + ---------------------------------------------------------------------------*) diff --git a/src/polling.mli b/src/polling.mli new file mode 100644 index 0000000..e61ed19 --- /dev/null +++ b/src/polling.mli @@ -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. + ---------------------------------------------------------------------------*)