Snippets in category Concurrency

  • Asynchronous sequences

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

    36 people like this
    Posted: 1 years ago by Tomas Petricek

  • Clojure's Atoms

    Clojure's Atoms are ref like structures, with the addition of (Compare And Swap) update semantics

    17 people like this
    Posted: 1 years ago by Nick Palladinos

  • Async hashing

    Async memory or file hashing

    8 people like this
    Posted: 1 years ago by Mauricio Scheffer

  • Async SMTP

    Async wrapper for SmtpClient (which is event-based)

    9 people like this
    Posted: 1 years ago by Mauricio Scheffer

  • Async TCP Server

    A basic, asynchronous TCP server

    15 people like this
    Posted: 1 years ago by Ryan Riley

  • 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

    3 people like this
    Posted: 1 years ago by Ryan Riley

  • Easy Wrapper for thread pool work

    An easy wrapper for the TPL that works nicely with (|>)

    8 people like this
    Posted: 1 years ago by Paul Greene

  • Clojure's Atoms

    Clojure's Atoms are ref like structures, with the addition of (Compare And Swap) update semantics

    16 people like this
    Posted: 1 years ago by Nick Palladinos

  • Simple HTTP server with Async workflow

    Simple HTTP server with Async workflow and Http Listener

    1 people like this
    Posted: 1 years ago by Ankur Dhama

  • Playing with async sequences

    Attempt to reimplement functions AsyncRead/AsyncReadLines from 'Rx on the server ' articles (by Jeffrey van Gogh) using idea of AsyncSequence (by Tomas Petricek)

    18 people like this
    Posted: 1 years ago by Vladimir Matveev

  • 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<HttpResponseMessage> 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.

    39 people like this
    Posted: 1 years ago by Ryan Riley

  • A little esoteric os

    Petrovich is more than just a programming language, it is a complete computer operating system and program development environment named after Ivan Petrovich Pavlov. Design Principles: * Provide an operating system and computer language that can learn and improve its performance in a natural manner. * Adapt to user feedback in an intelligent manner.

    9 people like this
    Posted: 1 years ago by Natallie Baikevich

  • Object oriented as it was supposed to be ?

    The snippet shows implementing object orientation using mail box processor. In this context object orientation have this simple definition: "Objects acts on message passing". The objects created this way are thread safe too :). Not sure how much practical this would be in todays context where object oriented has gone the wrong way.

    19 people like this
    Posted: 1 years ago by Ankur Dhama

  • Implementing active objects with a MailboxProcessor

    Mailbox processors can easily be used to implement active objects. This example shows how to do that with a reusable wrapper type and minimal boilerplate code in the actual class definitions. Supports both asynchronous calls and synchronous calls. For the latter case, exceptions are automatically propagated back to the caller.

    47 people like this
    Posted: 1 years ago by Wolfgang Meyer

  • Simple asynchronous functions

    The snippet demonstrates how to compose simple asynchronous functions and how to use try .. with to handle exceptions in asynchronous workflows.

    28 people like this
    Posted: 1 years ago by Tomas Petricek

  • TCP/IP Proxy

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

    11 people like this
    Posted: 1 years ago by Ademar Gonzalez

  • Web Crawler

    This snippet features an F# Web crawler that i'm already using in 2 applications (slightly modified). It's based on a scalable network of communicating agents that follow URLs extracted from HTML pages until reaching the specified limit.

    20 people like this
    Posted: 1 years ago by Taha Hachana

  • Actors acting as Lambdas

    The Untyped Lambda Calculus encoded as actors (F#'s MailboxProcessors)

    2 people like this
    Posted: 1 years ago by Nick Palladinos

  • Asynchronous Controller Helper

    The snippet declares a helper for creating asynchronous controllers for ASP.NET MVC 3. It declares a new base class for asynchronous actions that exposes a computation builder for writing actions using F# asynchronous workflows.

    7 people like this
    Posted: 1 years ago by Tomas Petricek

  • 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.

    8 people like this
    Posted: 1 years ago by Joel Mueller

  • Async File Crawl

    Async File Crawl

    6 people like this
    Posted: 11 months ago by fholm

  • 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#

    4 people like this
    Posted: 11 months ago by Ryan Riley

  • Throttling agent

    Agent that can be used for controlling the number of concurrently executing asynchronous workflows. The agent runs a specified number of operations concurrently and queues remaining pending requests. The queued work items are started as soon as one of the previous items completes.

    9 people like this
    Posted: 11 months ago by Tomas Petricek

  • Asynchronous Workflow Controller

    The snippet overrides default AsyncControllerActionInvoker so F# async workflows can be used for ASP.NET MVC 3. It declares a new base class for asynchronous controller. Controller method has to have return type Async<ActionResult>.

    3 people like this
    Posted: 11 months ago by Dmitry Morozov

  • Silverlight asynchronous WebService call with UI-thread syncronization dispatcher

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

    4 people like this
    Posted: 11 months ago by Tuomas Hietanen

  • Agent based ObjectPool

    This is a simple implementation of an object pool using an agent (MailboxProcessor). The pool is created with an initial number of object using the specified generator. The ObjectPool has three functions: Put: An item can be 'Put' into the pool. Get: An item can be taken from the pool ToListAndClear: A list of all the items in the pool is returned and the pool is cleared.

    7 people like this
    Posted: 11 months ago by 7sharp9

  • 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.

    3 people like this
    Posted: 11 months ago by Jason McCampbell

  • F# Future using lazy and a threading event

    F# Future using lazy and a threading event. Supports creating futures from functions or asyncs. Eager evaluation of can be specified.

    3 people like this
    Posted: 11 months ago by Ankur Dhama

  • Tetris

    Playable Tetris mini-game. Use arrow keys to move left and right and up to rotate, down to drop. Try it out in the browser on TryFSharp.org

    10 people like this
    Posted: 10 months ago by Phillip Trelford

  • Still Mouse Click Event

    Detects a mouse down then up event without a move.

    3 people like this
    Posted: 10 months ago by Phillip Trelford

  • Cancellable agent

    The snippet implements a wrapper for standard F# agent that can be cancelled using the IDisposable interface. This makes it possible to use the agent locally (e.g. inside asynchronous workflow). When it is no longer needed, the agent's body is cancelled.

    8 people like this
    Posted: 10 months ago by Tomas Petricek

  • Web Crawler extensions

    The snippet extends a web crawler from snippet http://fssnip.net/3K. It synchronizes all printing using an additional agent (so printed text does not interleave) and the crawling function returns an asynchronous workflow that returns when crawling completes.

    6 people like this
    Posted: 10 months ago by Tomas Petricek

  • Agent Based Scheduler

    An agent based scheduler, can be sent a single schedule message (ScheduleOnce) and multiple schedule message (Schedule). The schedule messages comprise of a function to receive the message, the message, an initial TimeSpan before the message is scheduled, and another timespan for the schedule repeat. Check out my blog below for more details: http://bit.ly/mK4prb

    4 people like this
    Posted: 10 months ago by 7sharp9

  • 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.

    3 people like this
    Posted: 10 months ago by Tomas Petricek

  • Synchronous, event-based and asynchronous HTTP proxy

    This snippet shows the implementation of three HTTP proxy servers in F#. The first is written using simple synchronous style (that isn't scalable). The second version uses event-based approach in the Node.js style, but is difficult to write. The third version uses F# async workflows and is both scalable and easy to write.

    5 people like this
    Posted: 10 months 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.

    5 people like this
    Posted: 10 months ago by Tomas Petricek

  • Erlang Ring problem

    Here's an attempt at the Erlang ring problem in F#.

    1 people like this
    Posted: 10 months ago by David Grenier

  • Return the first result using Async.Choice

    The snippet implements Async.Choice method that takes several workflows and creates a workflow, which returns the first result that was computed. After a workflow completes, remaining workflows are cancelled using the F# async cancellation mechanism. (The method doesn't handle exceptions.)

    6 people like this
    Posted: 9 months 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: 9 months ago by Nick Palladinos

  • Simple job processor

    Generic batch job processor using Mail box processor. Sending quit message using PostAndReply will ensure that all jobs are completed before returning. (Exception handling is responsibility of the job)

    4 people like this
    Posted: 9 months ago by Ankur Dhama

  • 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.

    8 people like this
    Posted: 9 months ago by Tomas Petricek

  • Growing Tree Algorithm for Maze Generation

    There are several maze creation algorithms (http://www.astrolog.org/labyrnth/algrithm.htm). The interesting point about Growing Tree one is that it turns into the others (for example, Recursive Backtracker and Prim's algo) when we choose the next step in different ways. Check it with tryfsharp.org.

    8 people like this
    Posted: 8 months ago by Natallie Baikevich

  • Call/CC for Async

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

    2 people like this
    Posted: 8 months ago by Ryan Riley

  • 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.

    5 people like this
    Posted: 8 months ago by Tomas Petricek

  • 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: 8 months ago by Tomas Petricek

  • Sliding window for Observable

    Implements the Observable.windowed function that creates an observable returning a sliding window. The function is an observable version of Seq.observable. The implementation uses a simple F# agent that keeps partial windows and sends them to an observer.

    3 people like this
    Posted: 8 months 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.)

    3 people like this
    Posted: 7 months ago by Tomas Petricek

  • Simple timed-expiry cache

    Basic thread-safe timed-expiry cache, implemented as a MailboxProcessor.

    3 people like this
    Posted: 6 months ago by Yusuf Motara

  • 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: 6 months ago by Ryan Riley

  • 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.

    2 people like this
    Posted: 6 months ago by Tomas Petricek

  • The dining philosophers

    The dining philosophers problem implemented using a waiter.

    4 people like this
    Posted: 6 months ago by Alex Muscar

  • 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.

    3 people like this
    Posted: 4 months ago by Tomas Petricek

  • Pong

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

    5 people like this
    Posted: 3 months ago by Phillip Trelford

  • Async.Parallel2 and Async.Parallel3

    Async.Parallel2 and Async.Parallel3, for running three Async's in parallel as thread pool tasks. Alternative versions given which use Async.Parallel under the hood.

    13 people like this
    Posted: 3 months ago by Don Syme

  • 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: 3 months ago by Andrei Kolomentsev

  • TicTacToe(Joinads Example)

    TicTacToe game simulator implemented by using Joinads(http://tomasp.net/blog/joinads-async-prog.aspx). Game logic in this snippet was simplified so nicely by using Joinads. You can run this snippet on Try Joinads (http://tryjoinads.org/).

    3 people like this
    Posted: 3 months ago by nagat01

  • Async HTTP server

    Creating an asynchronous HTTP Server in F#.

    6 people like this
    Posted: 1 months ago by Julian Kay

  • Monadic transactions for Clojure-style atoms

    This is a simple implementation of a monadic transaction builder for Clojure-style atoms. Based on original code by Nick Palladinos.

    10 people like this
    Posted: 1 months ago by Eirik Tsarpalis

  • Fun with Ping and Pong

    Yet another ping pong sample with agents.

    3 people like this
    Posted: 22 days ago by Ryan Riley

  • Ping and Pong go Chunking Along

    Parameterizing pong allows us to do even more fun things. Here we use a few message types to allow stateful consumption of data sent by ping to its pongs.

    1 people like this
    Posted: 21 days ago by Ryan Riley

  • OminaisuusStorage-testi

    Korjasin modulen P:n olemaan isolla... :-)

    1 people like this
    Posted: 19 days ago by

  • Async Primitives

    A set of Async primitives as described by Dave Thomas [1] (and derived from Stephen Toub [2]). [1] http://moiraesoftware.com/blog/2012/04/22/back-to-the-primitive-ii/ [2] http://blogs.msdn.com/b/pfxteam/archive/2012/02/11/10266923.aspx

    1 people like this
    Posted: 9 days ago by Ryan Riley