async-fx
Simplifies web, file, and parallel tasks with TypeScript async/await
This package makes it easier to perform web requests, access files, call asynchronous functions in parallel using TypeScript and async/await.
This package bundles the following: (each of which is also available individually if desired)
Getting Started
Make sure you're running Node v4 and TypeScript 1.7 or higher...
$ node -v
v4.2.6
$ npm install -g typescript tsd
$ tsc -v
Version 1.7.5
Install the async-fx package...
$ npm install async-fx
Install required typings definitions for the Node.js API...
$ tsd install node
Write some code...
; { var urls = 'http://google.com/' 'http://bing.com/' 'http://yahoo.com/'; var list = await Parallel; await Parallel; console;};
Save the above to a file (index.ts), build and run it!
$ tsc index.ts typings/node/node.d.ts --target es6 --module commonjs
$ node index.js
file "Google.html" written
file "Yahoo.html" written
file "Bing.html" written
done
More Examples
Read a set of three text files, one at a time...
var data1 = await File;var data2 = await File;var data3 = await File;
Get the current weather forecast from a JSON feed...
var url = 'http://query.yahooapis.com/v1/public/yql?q=select+item+from+weather.forecast+where+location%3D%2292679%22&format=json';var data = await WebRequestjson<any>url;console;
Append a line into an arbitrary series of text files, processing each operation in parallel...
var files = 'data1.log' 'data2.log' 'data3.log';await Parallel;
Get the top level page content from an arbitrary series of urls, running each request in parallel...
var urls = 'http://google.com/' 'http://bing.com/' 'http://yahoo.com/';var result = await Parallel;
Get two pages sleeping for 2 seconds in between...
var page1 = await WebRequest;await ;var page2 = await WebRequest;