Snippets tagged asynchronous
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 PetricekSimple 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 PetricekSynchronous, 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 PetricekAsynchronous 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
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 PetricekDownload 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 PetricekCaching 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 PetricekAsync.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