faraday_lwt.ml 654 B

12345678910111213141516171819202122232425
  1. open Lwt
  2. let serialize t ~yield ~writev =
  3. let shutdown () =
  4. Faraday.close t;
  5. (* It's necessary to drain the serializer in order to free any buffers that
  6. * may be be queued up. *)
  7. ignore (Faraday.drain t);
  8. in
  9. let rec loop t =
  10. match Faraday.operation t with
  11. | `Writev iovecs ->
  12. writev iovecs
  13. >>= (function
  14. | `Closed -> shutdown (); return () (* XXX(seliopou): this should be reported *)
  15. | `Ok n -> Faraday.shift t n; loop t)
  16. | `Yield ->
  17. yield t >>= fun () -> loop t
  18. | `Close -> return ()
  19. in
  20. catch
  21. (fun () -> loop t)
  22. (fun exn ->
  23. shutdown ();
  24. fail exn)