package lwt
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Promises and event-driven I/O
Install
dune-project
Dependency
Authors
Maintainers
Sources
6.1.0.tar.gz
md5=16d58c8295b5273e58779db0ad1f967a
sha512=d5eafe2f5d2dc576b76db15b84caf69d673cb3d736dc3e40b239e6a42c6036658c78bd4b883e9f2b9f627c144be515b1824f1f2de9d79c05d5744c456fb63257
doc/src/lwt.unix/lwt_gc.ml.html
Source file lwt_gc.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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85(* This file is part of Lwt, released under the MIT license. See LICENSE.md for details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *) (* [Lwt_sequence] is deprecated – we don't want users outside Lwt using it. However, it is still used internally by Lwt. So, briefly disable warning 3 ("deprecated"), and create a local, non-deprecated alias for [Lwt_sequence] that can be referred to by the rest of the code in this module without triggering any more warnings. *) module Lwt_sequence = Lwt_sequence let ensure_termination t = if Lwt.state t = Lwt.Sleep then begin let hook = Lwt_main.Exit_hooks.add_first (fun _ -> t) in (* Remove the hook when t has terminated *) ignore ( Lwt.finalize (fun () -> t) (fun () -> Lwt_main.Exit_hooks.remove hook; Lwt.return_unit)) end let finaliser f = (* In order not to create a reference to the value in the notification callback, we use an initially unset option cell which will be filled when the finaliser is called. *) let opt = ref None in let id = Lwt_unix.make_notification ~once:true (fun () -> match !opt with | None -> assert false | Some x -> opt := None; ensure_termination (f x)) in (* The real finaliser: fill the cell and send a notification. *) (fun x -> opt := Some x; Lwt_unix.send_notification id) let finalise f x = Gc.finalise (finaliser f) x (* Exit hook for a finalise_or_exit *) let foe_exit f called weak () = match Weak.get weak 0 with | None -> (* The value has been garbage collected, normally this point is never reached *) Lwt.return_unit | Some x -> (* Just to avoid double finalisation *) Weak.set weak 0 None; if !called then Lwt.return_unit else begin called := true; f x end (* Finaliser for a finalise_or_exit *) let foe_finaliser f called hook = finaliser (fun x -> (* Remove the exit hook, it is not needed anymore. *) Lwt_main.Exit_hooks.remove hook; (* Call the real finaliser. *) if !called then Lwt.return_unit else begin called := true; f x end) let finalise_or_exit f x = (* Create a weak pointer, so the exit-hook does not keep a reference to [x]. *) let weak = Weak.create 1 in Weak.set weak 0 (Some x); let called = ref false in let hook = Lwt_main.Exit_hooks.add_first (foe_exit f called weak) in Gc.finalise (foe_finaliser f called hook) x
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>