Multiple items
type Async
static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member AwaitTask : task:Task -> Async<unit>
static member AwaitTask : task:Task<'T> -> Async<'T>
static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
static member CancelDefaultToken : unit -> unit
static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg:'Arg1 * beginAction:('Arg1 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * beginAction:('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * arg3:'Arg3 * beginAction:('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromContinuations : callback:(('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Ignore : computation:Async<'T> -> Async<unit>
static member OnCancel : interruption:(unit -> unit) -> Async<IDisposable>
static member Parallel : computations:seq<Async<'T>> -> Async<'T []>
static member RunSynchronously : computation:Async<'T> * ?timeout:int * ?cancellationToken:CancellationToken -> 'T
static member Sleep : millisecondsDueTime:int -> Async<unit>
static member Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:CancellationToken -> Task<'T>
static member StartChild : computation:Async<'T> * ?millisecondsTimeout:int -> Async<Async<'T>>
static member StartChildAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions -> Async<Task<'T>>
static member StartImmediate : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartWithContinuations : computation:Async<'T> * continuation:('T -> unit) * exceptionContinuation:(exn -> unit) * cancellationContinuation:(OperationCanceledException -> unit) * ?cancellationToken:CancellationToken -> unit
static member SwitchToContext : syncContext:SynchronizationContext -> Async<unit>
static member SwitchToNewThread : unit -> Async<unit>
static member SwitchToThreadPool : unit -> Async<unit>
static member TryCancelled : computation:Async<'T> * compensation:(OperationCanceledException -> unit) -> Async<'T>
static member CancellationToken : Async<CancellationToken>
static member DefaultCancellationToken : CancellationToken

Full name: Microsoft.FSharp.Control.Async

--------------------
type Async<'T> =
  interface
    abstract member Start : ('T -> unit) -> unit
  end

Full name: index.Async<_>
abstract member Async.Start : ('T -> unit) -> unit

Full name: index.Async`1.Start
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
type Task<'T> =
  interface
    abstract member OnCompleted : (unit -> unit) -> unit
    abstract member Value : 'T option
  end

Full name: index.Task<_>
abstract member Task.Value : 'T option

Full name: index.Task`1.Value
type 'T option = Option<'T>

Full name: Microsoft.FSharp.Core.option<_>
abstract member Task.OnCompleted : (unit -> unit) -> unit

Full name: index.Task`1.OnCompleted
type IObservable<'T> =
  interface
    abstract member AddHandler : ('T -> unit) -> (unit -> unit)
  end

Full name: index.IObservable<_>
abstract member IObservable.AddHandler : ('T -> unit) -> (unit -> unit)

Full name: index.IObservable`1.AddHandler
type AsyncSeq<'T> = Async<AsyncSeqRes<'T>>

Full name: index.AsyncSeq<_>
type AsyncSeqRes<'T> =
  | Nil
  | Cons of 'T * AsyncSeq<'T>

Full name: index.AsyncSeqRes<_>
union case AsyncSeqRes.Nil: AsyncSeqRes<'T>
union case AsyncSeqRes.Cons: 'T * AsyncSeq<'T> -> AsyncSeqRes<'T>

Observables, Events, Asynchronous Sequences and Other Wild Animals






Tomas Petricek, fsharpWorks & Alan Turing Institute
fsharpworks.com | tomas@tomasp.net | @tomaspetricek

Asyncs and tasks


Asynchronous workflows


1: 
2: 
type Async<'T> = 
  abstract Start : ('T -> unit) -> unit
  • Computation, not a task
  • Calls continuation once

Tasks


1: 
2: 
3: 
type Task<'T> = 
  abstract Value : option<'T> 
  abstract OnCompleted : (unit -> unit) -> unit
  • Running task, not a computation
  • Inherently mutable

Events and observables


Observable


1: 
2: 
type IObservable<'T> = 
  abstract AddHandler : ('T -> unit) -> (unit -> unit)
  • Calls continuation repeatedly
  • Returns function for cancelling subscription

Async sequences


Async sequences


1: 
2: 
3: 
4: 
type AsyncSeq<'T> = Async<AsyncSeqRes<'T>>
and AsyncSeqRes<'T> = 
  | Nil
  | Cons of 'T * AsyncSeq<'T>
  • Asynchronously ask for next value
  • Pull-based, not push-based

Summary

Events, observables and async sequences


If it is not easy, it is impossible!

Async for asynchronous computations
Tasks do not compose well

Observables for push-based streams
or Events if you want state sharing

Async sequences for pull-based streams



fsharpworks.com | tomas@tomasp.net | @tomaspetricek