From 7994a1672acf382a3780d9c69e8566a7f833d7dd Mon Sep 17 00:00:00 2001 From: Doug Patti Date: Mon, 16 Jul 2018 12:54:23 -0400 Subject: [PATCH 1/2] unset yield on flush If you ask a serializer to `yield`, then synchronously use it in such a way that you no longer want it to yield, there is no way to "undo" the yield aside from using `operation` twice and ignoring the first yield. The semantics of `flush` should be that it unsets any possible `yield` flag so that the next operation has a chance to read pending iovecs. I did not include tests, particularly because this was difficult to encapsulate with the given framework. We need to be able to inspect the state of the serializer without closing it, and all current serialize functions do close it in order to dump the contents to a string or bigstring. --- lib/faraday.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/faraday.ml b/lib/faraday.ml index 74fd79a..f25db14 100644 --- a/lib/faraday.ml +++ b/lib/faraday.ml @@ -203,6 +203,7 @@ let flush_buffer t = end let flush t f = + t.yield <- false; flush_buffer t; if Buffers.is_empty t.scheduled then f () else Flushes.enqueue (t.bytes_received, f) t.flushed From d001dfa7be35acdf1b0831e7a7c01807c01ffb0e Mon Sep 17 00:00:00 2001 From: Spiros Eliopoulos Date: Tue, 17 Jul 2018 23:59:49 +0000 Subject: [PATCH 2/2] update documentation --- lib/faraday.mli | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/faraday.mli b/lib/faraday.mli index 4c5dcbc..11412bd 100644 --- a/lib/faraday.mli +++ b/lib/faraday.mli @@ -215,7 +215,9 @@ val yield : t -> unit val flush : t -> (unit -> unit) -> unit (** [flush t f] registers [f] to be called when all prior writes have been successfully completed. If [t] has no pending writes, then [f] will be - called immediately. *) + called immediately. If {!yield} was recently called on [t], then the effect + of the [yield] will be ignored so that client code has an opportunity to + write pending output, regardless of how it handles [`Yield] operations. *) val close : t -> unit (** [close t] closes [t]. All subsequent write calls will raise, and any