package faraday-async
Async support for Faraday
Install
Dune Dependency
Authors
Maintainers
Sources
0.7.2.tar.gz
sha256=e887a93d1fe730b42b50af8f557b9b71afe04e8af0ffad05e5449bd0617a41cf
md5=61bb83e1a4bed100eb0bd1365878e3a1
doc/src/faraday-async/faraday_async.ml.html
Source file faraday_async.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
open Core open Async module Unix = Core.Unix let serialize t ~yield ~writev = let shutdown () = Faraday.close t; (* It's necessary to drain the serializer in order to free any buffers that * be queued up. *) ignore (Faraday.drain t) in let rec loop t = match Faraday.operation t with | `Writev iovecs -> writev iovecs >>= (function | `Closed -> shutdown (); return () (* XXX(seliopou): this should be reported *) | `Ok n -> Faraday.shift t n; loop t) | `Yield -> yield t >>= fun () -> loop t | `Close -> return () in try_with ~extract_exn:true (fun () -> loop t) >>| function | Result.Ok () -> () | Result.Error exn -> shutdown (); raise exn let writev_of_fd fd = let badfd = failwithf "writev_of_fd got bad fd: %s" (Fd.to_string fd) in let finish result = let open Unix.Error in match result with | `Ok n -> return (`Ok n) | `Already_closed -> return `Closed | `Error (Unix.Unix_error ((EWOULDBLOCK | EAGAIN), _, _)) -> begin Fd.ready_to fd `Write >>| function | `Bad_fd -> badfd () | `Closed -> `Closed | `Ready -> `Ok 0 end | `Error (Unix.Unix_error (EBADF, _, _)) -> badfd () | `Error exn -> Deferred.don't_wait_for (Fd.close fd); raise exn in fun iovecs -> let iovecs = Array.of_list_map iovecs ~f:(fun iovec -> let { Faraday.buffer; off = pos; len } = iovec in Unix.IOVec.of_bigstring ~pos ~len buffer) in if Fd.supports_nonblock fd then finish (Fd.syscall fd ~nonblocking:true (fun file_descr -> Bigstring_unix.writev_assume_fd_is_nonblocking file_descr iovecs)) else Fd.syscall_in_thread fd ~name:"writev" (fun file_descr -> Bigstring_unix.writev file_descr iovecs) >>= finish
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>