Skip to content

Instantly share code, notes, and snippets.

@kjnilsson
Last active August 29, 2015 14:08
Show Gist options
  • Save kjnilsson/b9985c8b37c391c053c2 to your computer and use it in GitHub Desktop.
Save kjnilsson/b9985c8b37c391c053c2 to your computer and use it in GitHub Desktop.
How do I make this properly async?
type ContentLengthHandler() =
inherit DelegatingHandler ()
override __.SendAsync (request, token) =
let resp = base.SendAsync(request, token).Result //GAH
match resp.Content with
| :? ObjectContent as oc ->
let s = oc.ReadAsStreamAsync().Result //GAH
resp.Content <- new StreamContent(s)
resp.Content.Headers.ContentLength <- Nullable (int64 s.Length)
Task.FromResult resp
| _ ->
Task.FromResult resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment