Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
This controls flow by events like flags.
JavaScript CoffeeScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
README.md
package.json

README.md

EventSync

This controls flow by events like flags.

Usage

If you want to make a http server serving a static file and load file before handling the requests, you can put http.createServer() in the callback of fs.readFile(). But it makes a too deep nest. Now, with EventSync, you can write the code like this.

var fs = require('fs'),
    http = require('http'),
    EventSync = require('evsync');

var evsync = new EventSync();

fs.readFile('foo.txt', 'utf8', function (err, data) {
  if (err) {
    evsync.open('error', err);
  } else {
    evsync.open('load', data);
  }
});

http.createServer(function (req, res) {
  evsync.once('load', function (file) {
    res.writeHead(200);
    res.end(file);
  });
  evsync.once('error', function (err) {
    res.writeHead(500);
    res.end('Failed to load the file.');
  });
}).listen(8124);
Something went wrong with that request. Please try again.