Skip to content

Commit

Permalink
Merge pull request #171 from inhabitedtype/call-if-some
Browse files Browse the repository at this point in the history
call-if-some: add Optional_thunk.call_if_some and use it
  • Loading branch information
seliopou authored Apr 3, 2020
2 parents fdda189 + 1e5dcee commit 16a2486
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/body.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let schedule_bigstring t ?off ?len (b:Bigstringaf.t) =
let ready_to_write t =
let callback = t.when_ready_to_write in
t.when_ready_to_write <- Optional_thunk.none;
Optional_thunk.unchecked_value callback ()
Optional_thunk.call_if_some callback

let flush t kontinue =
Faraday.flush t.faraday kontinue;
Expand Down
1 change: 1 addition & 0 deletions lib/optional_thunk.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ let some f =

let is_none t = t == none
let is_some t = not (is_none t)
let call_if_some t = t ()
let unchecked_value t = t
1 change: 1 addition & 0 deletions lib/optional_thunk.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ val some : (unit -> unit) -> t
val is_none : t -> bool
val is_some : t -> bool

val call_if_some : t -> unit
val unchecked_value : t -> unit -> unit
2 changes: 1 addition & 1 deletion lib/reqd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let create error_handler request request_body writer response_body_buffer =
let done_waiting when_done_waiting =
let f = !when_done_waiting in
when_done_waiting := Optional_thunk.none;
Optional_thunk.unchecked_value f ()
Optional_thunk.call_if_some f

let request { request; _ } = request
let request_body { request_body; _ } = request_body
Expand Down
4 changes: 2 additions & 2 deletions lib/server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let yield_reader t k =
let wakeup_reader t =
let f = t.wakeup_reader in
t.wakeup_reader <- Optional_thunk.none;
Optional_thunk.unchecked_value f ()
Optional_thunk.call_if_some f
;;

let on_wakeup_writer t k =
Expand All @@ -105,7 +105,7 @@ let on_wakeup_writer t k =
let wakeup_writer t =
let f = t.wakeup_writer in
t.wakeup_writer <- Optional_thunk.none;
Optional_thunk.unchecked_value f ()
Optional_thunk.call_if_some f
;;

let transfer_writer_callback t reqd =
Expand Down

0 comments on commit 16a2486

Please sign in to comment.