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.

    109 people like this

    Posted: 15 years ago by Tomas Petricek

  • Async SMTP

    Async wrapper for SmtpClient (which is event-based)

    15 people like this

    Posted: 14 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: 14 years ago by Ryan Riley

  • Simple HTTP server with Async workflow

    Simple HTTP server with Async workflow and Http Listener

    12 people like this

    Posted: 14 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.

    57 people like this

    Posted: 14 years ago by Ryan Riley

  • TCP/IP Proxy

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

    24 people like this

    Posted: 14 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.

    13 people like this

    Posted: 14 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#

    6 people like this

    Posted: 14 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: 14 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: 14 years ago by Jason McCampbell

  • Still Mouse Click Event

    Detects a mouse down then up event without a move.

    4 people like this

    Posted: 14 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: 14 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.

    7 people like this

    Posted: 14 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: 14 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.

    11 people like this

    Posted: 14 years ago by Tomas Petricek

  • Download stock prices as async sequence

    The snippet uses asynchronous sequences (from F# AsyncExtensions) to download historical stock data from Yahoo. Data is downloaded in a buffered way on demand (as needed) and returned line by line. The sample then prints OHLC values for first 30 items.

    6 people like this

    Posted: 14 years ago by Tomas Petricek

  • Async.Choose operation

    Non-deterministic choice operation for F# asynchronous workflows - creates a workflow that returns the result of one of two asynchronous workflows, depending on which completes first. (The other workflow is not cancelled.)

    4 people like this

    Posted: 14 years ago by Tomas Petricek

  • Caching agent

    Agent that keeps a cache of web pages that were downloaded previously. The agent handles messages to add and get data as well as message to clear the cache.

    7 people like this

    Posted: 14 years ago by Tomas Petricek

  • F# counter agent

    The snippet shows a simple F# agent that calculates average from the received values. It supports one message for adding numbers to the statistics and one for resetting the state. Moreover, the agent limits the processing rate to 1 message per second.

    6 people like this

    Posted: 13 years ago by Tomas Petricek

  • 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: 13 years ago by Andrei Kolomentsev

  • Async HTTP server

    Creating an asynchronous HTTP Server in F#.

    6 people like this

    Posted: 13 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: 13 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: 13 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.

    6 people like this

    Posted: 13 years ago by Tomas Petricek

  • Async.Choice

    A simple extension method for asynchronous non-deterministic computations.

    4 people like this

    Posted: 13 years ago by Nick Palladinos

  • Faster exception handling with Async.Raise

    Code by me and Nick Palladinos.

    2 people like this

    Posted: 13 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: 12 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.

    18 people like this

    Posted: 12 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: 12 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: 11 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: 11 years ago by mavnn

  • Async demo

    Async demo...

    3 people like this

    Posted: 11 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.

    12 people like this

    Posted: 11 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.

    7 people like this

    Posted: 11 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: 11 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

    7 people like this

    Posted: 10 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: 10 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: 10 years ago by Ryan Riley

  • Game Evolution

    Game evolution

    2 people like this

    Posted: 10 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: 10 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: 10 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

    2 people like this

    Posted: 10 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: 9 years ago by cboudereau

  • Async ParallelWithThrottle

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

    8 people like this

    Posted: 9 years 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: 8 years ago by Eirik Tsarpalis

  • WPF async access.

    Computation builder for async access.

    1 people like this

    Posted: 8 years ago by Zhukoff Dima

  • Executes Async's one by one

    Executes Async's one by one

    0 people like this

    Posted: 7 years ago by Yuri Martynov

  • Awaiting arbitrary C# awaitables

    Uses SRTPs to define a general purpose adapter for awaiting arbitrary C# awaitables in F# async workflows.

    3 people like this

    Posted: 5 years ago by Eirik Tsarpalis

  • Multithreaded Proxy Checker in F#

    The text file containing proxies named "proxlist.txt", in the form of "ip:port" per line is the input source, the program will attempt to establish a connection through each proxy to a provided URL. Proxies that passed the test will be written out to the file "results.txt" in the form "ip:port duration_of_connection_attempt"

    2 people like this

    Posted: 4 years ago by Vladimir Demydov