Skip to content

Instantly share code, notes, and snippets.

@davidlhw
Created June 13, 2023 08:11
Show Gist options
  • Save davidlhw/7632d48267f511013ec435711c0343bf to your computer and use it in GitHub Desktop.
Save davidlhw/7632d48267f511013ec435711c0343bf to your computer and use it in GitHub Desktop.
A simple wrapper to handle IAsyncEnumerable in F#
type System.Collections.Generic.IAsyncEnumerable<'T> with
member this.AsTask () = task {
let mutable nxt = true
let output = ResizeArray()
let enumerator = this.GetAsyncEnumerator()
while nxt do
let! next = enumerator.MoveNextAsync()
nxt <- next
if nxt then output.Add enumerator.Current
return output.ToArray()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment