Sha256: 0d4b85d4b1a73e9684a207e246c160a6af1f54230b12ffa20fe9ae310b06a973

Contents?: true

Size: 1.24 KB

Versions: 110

Compression:

Stored size: 1.24 KB

Contents

Run Async
=========

[![npm](https://badge.fury.io/js/run-async.svg)](http://badge.fury.io/js/run-async) [![tests](https://travis-ci.org/SBoudrias/run-async.svg?branch=master)](http://travis-ci.org/SBoudrias/run-async) [![dependencies](https://david-dm.org/SBoudrias/run-async.svg?theme=shields.io)](https://david-dm.org/SBoudrias/run-async)

Utility method to run function either synchronously or asynchronously using the common `this.async()` style.

This is useful for library author accepting sync or async functions as parameter. `runAsync` will always run them as async method, and normalize the function handling.

Installation
=========

```bash
npm install --save run-async
```

Usage
=========

```js
var runAsync = require('run-async');

// In Async mode:
var asyncFn = function (a) {
  var done = this.async();

  setTimeout(function () {
    done('running: ' + a);
  }, 10);
};

runAsync(asyncFn, function (answer) {
  console.log(answer); // 'running: async'
}, 'async');

// In Sync mode:
var syncFn = function (a) {
  return 'running: ' + a;
};

runAsync(asyncFn, function (answer) {
  console.log(answer); // 'running: sync'
}, 'sync');
```

Licence
========

Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart)  
Licensed under the MIT license.

Version data entries

110 entries across 110 versions & 5 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/run-async/README.md
govuk_publishing_components-17.21.0 node_modules/run-async/README.md
govuk_publishing_components-17.20.0 node_modules/run-async/README.md
govuk_publishing_components-17.19.1 node_modules/run-async/README.md
govuk_publishing_components-17.19.0 node_modules/run-async/README.md
govuk_publishing_components-17.18.0 node_modules/run-async/README.md
govuk_publishing_components-17.17.0 node_modules/run-async/README.md
govuk_publishing_components-17.16.0 node_modules/run-async/README.md
govuk_publishing_components-17.15.0 node_modules/run-async/README.md
govuk_publishing_components-17.14.0 node_modules/run-async/README.md
govuk_publishing_components-17.13.0 node_modules/run-async/README.md
govuk_publishing_components-17.12.2 node_modules/run-async/README.md
govuk_publishing_components-17.12.1 node_modules/run-async/README.md
govuk_publishing_components-17.12.0 node_modules/run-async/README.md
govuk_publishing_components-17.11.0 node_modules/run-async/README.md
govuk_publishing_components-17.10.0 node_modules/run-async/README.md
govuk_publishing_components-17.9.0 node_modules/run-async/README.md
govuk_publishing_components-17.8.0 node_modules/run-async/README.md
govuk_publishing_components-17.7.0 node_modules/run-async/README.md
govuk_publishing_components-17.6.1 node_modules/run-async/README.md