Something went wrong. Try again.
ocaml
Something went wrong. Try again.
964 B · 30 lines
OCaml
at pp-ast
12345678910111213141516171819202122232425262728293031(* * SPDX-FileCopyrightText: 2024 The Forester Project Contributors * SPDX-FileCopyrightText: 2026 The Forester Project Contributors * * SPDX-License-Identifier: GPL-3.0-or-later *)
open Forester_preludeopen Brropen Brr_io.Fetch
let text (url : Jstr.t) : (string, Jv.Error.t) result Fut.t = let open Fut.Result_syntax in let* res = request @@ Request.v ~init:(Request.init ()) url in let* text = Body.text @@ Response.as_body res in Fut.return @@ Ok (Jstr.to_string text)
let json (url : Jstr.t) (codec : 'a Jsont.t) : ('a, Jv.Error.t) result Fut.t = let open Fut.Result_syntax in let* res = request @@ Request.v ~init:(Request.init ()) url in let* body = Body.json (Response.as_body res) in Fut.return @@ Jsont_brr.decode_jv codec body
let rec poll ~(ms : int) (f : unit -> bool Fut.t) : unit = ignore begin let@ () = G.set_timeout ~ms in let@ continue = Fut.await @@ f () in if continue then poll ~ms f end