You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -177,6 +178,8 @@ The most common use is when you have a function that receives no parameters, but
177
178
let appendSomeTextToFile () = // without unit, only one line would be appended to the file
178
179
System.IO.File.AppendAllText($"{__SOURCE_DIRECTORY__}/file.txt", "New line")
179
180
181
+
<divid="functions-signatures"></div>
182
+
180
183
### Signatures and Explicit Typing
181
184
182
185
Function signatures are useful for quickly learning the input and output of functions. The last type is the return type and all preceding types are the input types.
@@ -740,6 +743,112 @@ Another way of implementing interfaces is to use *object expressions*.
740
743
741
744
*Partial active patterns* share the syntax of parameterized patterns but their active recognizers accept only one argument.
742
745
746
+
<divid="asynchronous-programming"></div>
747
+
748
+
## Asynchronous Programming
749
+
750
+
F# asynchronous programming is centered around two core concepts: async computations and tasks.
let asyncComputation = runAsync 5 // returns Async<unit> and does not print anything
778
+
let newTask = runTask 3 // returns System.Threading.Tasks.Task<unit> and outputs: "Started Task" <3 second delay> "Completed Task"
779
+
780
+
asyncComputation |> Async.RunSynchronously // this now runs the async computation
781
+
newTask.Wait() // this will have already completed by this point
782
+
783
+
// Output:
784
+
// Started Task
785
+
// Created Async
786
+
// Completed Task
787
+
// Completed Async
788
+
789
+
### Async and Task Interop
790
+
791
+
As F# sits in .NET, and a lot of the codebase uses the C# async/await, the majority of actions are going to be executed and tracked using `System.Threading.Tasks.Task<'T>`s.
792
+
793
+
#### Async.AwaitTask
794
+
795
+
This converts a Task into an async computation. It has the [signature](#functions-signatures): `Task<'T>` -> `Async<'T>`
0 commit comments