Snippets tagged async

  • Asynchronous sequences

    An asynchronous sequence is similar to the seq type, but the elements of the sequence are generated asynchronously without blocking the caller as in Async. This snippet declares asynchronous sequence and uses it to compare two files in 1k blocks.

    104 people like this

    Posted: 6 years ago by Tomas Petricek

  • Async SMTP

    Async wrapper for SmtpClient (which is event-based)

    15 people like this

    Posted: 6 years ago by Mauricio Scheffer

  • Async to IObservable

    Wraps an Async as an IObservable to allow easier consumption by other .NET languages. Many thanks to desco for his help: http://cs.hubfs.net/forums/thread/16545.aspx

    5 people like this

    Posted: 6 years ago by Ryan Riley

  • Simple HTTP server with Async workflow

    Simple HTTP server with Async workflow and Http Listener

    9 people like this

    Posted: 6 years ago by Ankur Dhama

  • Composable WCF Web API using Async

    A functional wrapper around the new WCF Web APIs (http://wcf.codeplex.com/). Composition is achieved through the use of the HttpRequestMessage -> Async signature. Pushing the app calls in the MessageHandler intercepts all requests and allows you to take control at the earliest point possible before operation selection occurs. Extending this slightly to call the innerChannel's SendAsync would allow you to create a middleware layer that would work both with this and other, normal Web API services.

    56 people like this

    Posted: 6 years ago by Ryan Riley

  • TCP/IP Proxy

    A minimal TCP/IP proxy implementation with F# asynchronous workflows

    24 people like this

    Posted: 6 years ago by Ademar Gonzalez

  • Async SNTP client

    An asynchronous SNTP client that can retrieve the current time from an internet time server (such as time-a.nist.gov) and optionally update the local system clock to match. Demonstrates async UDP communication, bit-shifting, and native interop/PInvoke.

    12 people like this

    Posted: 5 years ago by Joel Mueller

  • Sequence Generator from Async

    Generates a sequence using a sequence generator and Async.StartWithContinuations. This is an attempt at modeling the OWIN delegate structure in F#

    5 people like this

    Posted: 5 years ago by Ryan Riley

  • Silverlight asynchronous WebService call with UI-thread syncronization dispatcher

    You can use this code to make a async WebRequest from Silverlight to update ViewModel.

    5 people like this

    Posted: 5 years ago by Tuomas Hietanen

  • F# Future

    Similar to an async { } block but captures the result for future consumption. This structure can be very useful for performing multiple result-returning operations in parallel when the results aren't needed immediately. For example, performing several read/transform operations or pre-populating a cache with yet-to-be computed values. Microsoft's Task Parallel Library in .NET 4.0 includes a Future implementation so this version is only needed on earlier .NET versions. Comments, suggestions, and improvements are always welcome.

    4 people like this

    Posted: 5 years ago by Jason McCampbell

  • Still Mouse Click Event

    Detects a mouse down then up event without a move.

    4 people like this

    Posted: 5 years ago by Phillip Trelford

  • Extensions for HTTP servers

    This snippet extends several types from the System.Net namespace. It provides an easy to use API for creating asynchronous (as well as synchronous) HTTP servers using F# asynchronous workflows.

    4 people like this

    Posted: 5 years ago by Tomas Petricek

  • Asynchronous HTTP proxy with chunking and caching

    This snippet shows two improvements to asynchronous HTTP proxy from: http://fssnip.net/6e. First extension is to process page in chunks (instead of downloading the entire content first). The second extension is to use simple agent-based in-memory cache for previously visited pages.

    6 people like this

    Posted: 5 years ago by Tomas Petricek

  • Async based MapReduce

    Async is a very versatile structure, which has been used to compose CPU/IO bound computations. So it is very tempting to implement a MapReduce function based on Async and borrowing ideas from the theory of list homomorphisms.

    7 people like this

    Posted: 5 years ago by Nick Palladinos

  • AsyncSeq - Introduction and Crawler

    This snippet demonstrates programming using asynchronous sequences. It contains (hidden) implementation of AsyncSeq type and combinators for working with it. More importantly, it demonstrates how to use asynchronous sequences to implement a simple sequential on-demand crawler.

    10 people like this

    Posted: 5 years ago by Tomas Petricek

  • Call/CC for Async

    An implementation of call-with-current-continuation for Async.

    2 people like this

    Posted: 5 years ago by Ryan Riley

  • Creating observable using Async.StartDisposable

    Implements a simple Async.StartDisposable extension that can be used to easily create IObservable values from F# asynchronous workflows. The method starts an asynchronous workflow and returns IDisposable that cancels the workflow when disposed.

    4 people like this

    Posted: 5 years ago by Tomas Petricek

  • F#-friendly SocketAsyncEventArgs

    The name is a bit trying, but the overall callback approach greatly simplifies the mechanism for calling and handling the System.Net.Sockets.Socket Async methods.

    0 people like this

    Posted: 5 years ago by Ryan Riley

  • The dining philosophers

    The dining philosophers problem implemented using a waiter.

    4 people like this

    Posted: 5 years ago by Alex Muscar

  • Pong

    Pong video game runnable inside TryFSharp.org. Player 1 keys 'Q' - up, 'A' - down. Player 2 keys 'P' - up, 'L' - down.

    7 people like this

    Posted: 5 years ago by Phillip Trelford

  • Async.Sleep with immediate cancellation

    Implementation of Async.Sleep in f# 2.0 doesn't allow break it execution until the time elapsed. Here is the alternate implementation which support immediate cancellation. According to discussion http://stackoverflow.com/questions/9041491/is-there-any-reason-why-async-sleep-can-not-be-canceled-immediately .

    2 people like this

    Posted: 5 years ago by Andrei Kolomentsev

  • Async HTTP server

    Creating an asynchronous HTTP Server in F#.

    6 people like this

    Posted: 4 years ago by Julian Kay

  • Get Assemblies from NuGet

    Given a NuGet package name, this code will download the package, extract it to a temp directory, and return a sequence of FileInfo objects representing assemblies from that package, with a preference for .NET 4.5 and 4.0 assemblies, if present. Requires the "DotNetZip" package.

    6 people like this

    Posted: 4 years ago by Joel Mueller

  • Asynchronous Entity Framework Query

    Entity Framework doesn't currently support async operations, but as long as the underlying provider is System.Data.SqlClient we can make it work.

    3 people like this

    Posted: 4 years ago by Joel Mueller

  • Asynchronous cancellation of a workflow

    The snippet implements Async.StartCancellable method that can be used to start a given workflow and then cancel it. The cancellation of the workflow is done asynchronously, which means that the caller will wait until the workflow is actually cancelled.

    4 people like this

    Posted: 4 years ago by Tomas Petricek

  • Async.Choice

    A simple extension method for asynchronous non-deterministic computations.

    3 people like this

    Posted: 4 years ago by Nick Palladinos

  • Faster exception handling with Async.Raise

    Code by me and Nick Palladinos.

    1 people like this

    Posted: 4 years ago by Eirik Tsarpalis

  • LazyAsync

    Allows to expose an F# async value in a C#-friendly API with the semantics of Lazy<> (compute on demand and guarantee only one computation)

    3 people like this

    Posted: 4 years ago by Gustavo Guerra

  • Extending async with await on tasks

    The snippet shows how to extend the built-in F# async computation builder with the ability to await standard .NET tasks using the let! keyword.

    16 people like this

    Posted: 4 years ago by Tomas Petricek

  • AsyncBuilder extension for maniplating other containers by using keyword

    AsyncBuilder extension for maniplating some other containers directory in asynchronous workflow. Bind methods in the extension enables you to retrieve inner values of 'a IObservable and 'a IEvent by using let! or do! keyword without Async.AwaitEvent or AsyncAwaitObservable. For method in the extension omits let! binding. Yield method in the extension enables you to yield value in for expression in asynchronous workflow.

    3 people like this

    Posted: 3 years ago by nagat01

  • Porting of AsyncOneManyLock to F#

    If you have read the awesome book by Jeffrey Richter CLR via C# 4 ed. you have discovered that there are more optimal ways for thread synchronization than the one provided by the BCL. One of them is the use of new asynchronous capabilities in order to create an asynchronous synchronization primitive. In the book it is presented an AsyncOneManyLock which is used for thread synchornization for code with a high demand for responsiveness and scalability. If you are an F# developer you know that the F# Asynchornous Workflow and the Task Parallel Library are different, so I decided to port this useful piece of code to F# and show you how to use it with an example.

    0 people like this

    Posted: 3 years ago by Antonio Parata

  • asyncChoose Computational Expression

    A simple computational expression to deal with asynchronous calls that return a choice type to signal failure. Useful for calling remote services that may fail - you can call the remote service with functions of type "request -> Async>" and then chain the results together.

    1 people like this

    Posted: 3 years ago by mavnn

  • Async demo

    Async demo...

    3 people like this

    Posted: 2 years ago by Tomas Petricek

  • Limit degree of parallelism using an agent

    The snippet implements a simple agent that limits the number of parallelism. When created, the agent takes the maximum number of tasks it can run in parallel. When it receives a "Start" message, it will then either run the task, or store it in a queue until earlier task ha completed.

    11 people like this

    Posted: 2 years ago by Tomas Petricek

  • Throttling agent

    Implements a simple agent that lets you throttle the degree of parallelism by limiting the number of work items that are processed in parallel.

    5 people like this

    Posted: 2 years ago by Tomas Petricek

  • "Fastest wins" parallel download with Hopac

    One of the main features of Hopac - selective synchronization using "alternatives". In this snippet we download three web pages in parallel and the one that finishes first "wins" (or the timeout alternative becomes available for picking). What's nice in this solution is that the other two downloading jobs are cancelled immediately when the winner/timeout is available (i.e. an implicitly provided to the Asyncs CancellationTokens are cancelled). Alts is highly composable and, for example, the whole Alt.choose [ ... ] thing could be nested in another Alt.choose or combined with <|> or <&> operators with another Alt and so on.

    3 people like this

    Posted: 2 years ago by Vasily Kirichenko

  • MailboxProcessor with exception handling and restarting

    An extension of MailboxProcessor that catches all unhandled exceptions, and ensures that the user-provided function is run repeatedly until it returns normally. Based on the HandlingMailbox defined by Tomas Petricek: fssnip.net/cj

    6 people like this

    Posted: 2 years ago by Anthony Perez

  • Fast Async Stream Copy

    This is a simple code implementation to copy Streams leveraging the Async workflow. After the first read, the write and read processes are done in parallel. I also used an Array of Array as buffer to avoid false sharing memory. An other improvment option could be to increase the buffer size if the copy is done in same machine.

    7 people like this

    Posted: 2 years ago by Riccardo Terrell

  • Web API AsyncApiActionInvoker

    Overrides the standard Web API ApiControllerActionInvoker with one that works with controller actions return F# Async<'T> results.

    5 people like this

    Posted: 2 years ago by Ryan Riley

  • Game Evolution

    Game evolution

    2 people like this

    Posted: 2 years ago by Paul Orland

  • Vsync Computation Expression

    The 'Vsync' (AKA, 'Variable Synchronization') computation expression that coheres into the Sync comp. expr. when SYNC is #defined, and into the Async comp. expr. otherwise.

    1 people like this

    Posted: 1 years ago by Bryan Edds

  • Generic command/request agent with error handling

    Generic command/request agent with error handling used to serialise posted commands and requests which are defined by closures. Useful in serialising communications to an instrument with a C API.

    3 people like this

    Posted: 1 years ago by Anton Tcholakov

  • Alternative Async.RunSynchronously

    An alternative Async.RunSynchronously implementation that avoids the performance bug as recorded in https://github.com/Microsoft/visualfsharp/issues/581

    1 people like this

    Posted: 1 years ago by Eirik Tsarpalis

  • Async task computation expression

    Async task computation expression, in order to avoid Async.AwaitTask for C# interop

    3 people like this

    Posted: 11 months ago by cboudereau

  • Async ParallelWithThrottle

    Implementation of ParallelWithThrottle to limit the number of threads created for an asynchronous Seq.map operation

    5 people like this

    Posted: 10 months ago by Riccardo Terrell

  • Async.AwaitTask that honors ambient cancellation semantics

    Related to https://github.com/Microsoft/visualfsharp/issues/2127

    1 people like this

    Posted: 2 months ago by Eirik Tsarpalis