Compare commits
	
		
			10 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e534d3a4b3 | |||
| 
						 | 
					7ba1195ac5 | ||
| 
						 | 
					34d8d7bbc5 | ||
| 
						 | 
					7fa166802a | ||
| 
						 | 
					0022ba5abe | ||
| 
						 | 
					2f6f9d5e8e | ||
| 
						 | 
					812950328d | ||
| 
						 | 
					ba81917d4f | ||
| 
						 | 
					c8875d8d40 | ||
| 
						 | 
					f761f9215c | 
							
								
								
									
										15
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								README.md
									
									
									
									
									
								
							@ -1,6 +1,8 @@
 | 
			
		||||
forEachAsync
 | 
			
		||||
forEachAsync.js
 | 
			
		||||
===
 | 
			
		||||
 | 
			
		||||
| A [Root](https://rootprojects.org) project
 | 
			
		||||
 | 
			
		||||
Analogous to `[].forEach`, but handles items asynchronously with a final callback passed to `then`.
 | 
			
		||||
 | 
			
		||||
This is the most essential piece of the [`ArrayAsync`](https://github.com/FuturesJS/ArrayAsync) package.
 | 
			
		||||
@ -19,7 +21,7 @@ Straight up, that's probably a bad idea and waste of time so I hope I don't actu
 | 
			
		||||
Screencast
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<http://youtu.be/O7egvEz4scA>
 | 
			
		||||
<https://youtu.be/O7egvEz4scA>
 | 
			
		||||
 | 
			
		||||
Usage
 | 
			
		||||
-----
 | 
			
		||||
@ -62,18 +64,17 @@ You can install from bower:
 | 
			
		||||
bower install --save forEachAsync@5.x
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Or download the raw file from <https://raw.github.com/FuturesJS/forEachAsync/master/forEachAsync.js>:
 | 
			
		||||
Or download the raw file from <https://git.coolaj86.com/coolaj86/foreachasync.js/raw/branch/master/foreachasync.js>:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
wget https://raw.github.com/FuturesJS/forEachAsync/master/forEachAsync.js
 | 
			
		||||
wget https://git.coolaj86.com/coolaj86/foreachasync.js/raw/branch/master/foreachasync.js
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
(function () {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  var forEachAsync = window.forEachAsync
 | 
			
		||||
    ;
 | 
			
		||||
  var forEachAsync = window.forEachAsync;
 | 
			
		||||
 | 
			
		||||
  // do stuff ...
 | 
			
		||||
}());
 | 
			
		||||
@ -85,7 +86,7 @@ Node Installation
 | 
			
		||||
===
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
npm install --save forEachAsync@5.x
 | 
			
		||||
npm install --save foreachasync@5.x
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
API
 | 
			
		||||
 | 
			
		||||
@ -2,17 +2,15 @@
 | 
			
		||||
;(function (exports) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  var BREAK = {}
 | 
			
		||||
    , exp = {}
 | 
			
		||||
    ;
 | 
			
		||||
  var BREAK = {};
 | 
			
		||||
  var exp = {};
 | 
			
		||||
 | 
			
		||||
  function create(PromiseA) {
 | 
			
		||||
    PromiseA = PromiseA.Promise || PromiseA;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    function forEachAsync(arr, fn, thisArg) {
 | 
			
		||||
      var result = PromiseA.resolve()
 | 
			
		||||
        ;
 | 
			
		||||
      var result = PromiseA.resolve();
 | 
			
		||||
 | 
			
		||||
      arr.forEach(function (item, k) {
 | 
			
		||||
        result = result.then(function () {
 | 
			
		||||
@ -26,8 +24,8 @@
 | 
			
		||||
            ret = result = fn(item, k, arr);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (!ret.then) {
 | 
			
		||||
            ret = PromiseA.resolve(result);
 | 
			
		||||
          if (!ret || !ret.then) {
 | 
			
		||||
            ret = PromiseA.resolve(ret);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          return ret.then(function (val) {
 | 
			
		||||
@ -61,24 +59,15 @@
 | 
			
		||||
  exports.create = forEachAsync.create = function () {};
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  /* globals Promise */
 | 
			
		||||
  if ('undefined' !== typeof Promise) {
 | 
			
		||||
    exp.forEachAsync = create(Promise);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    try {
 | 
			
		||||
     exp.forEachAsync = create(require('bluebird'));
 | 
			
		||||
    } catch(e) {
 | 
			
		||||
    if ('undefined' !== typeof Promise) {
 | 
			
		||||
      exp.forEachAsync = create(Promise);
 | 
			
		||||
    } else {
 | 
			
		||||
      try { 
 | 
			
		||||
       exp.forEachAsync = create(require('es6-promise'));
 | 
			
		||||
      } catch(e) {
 | 
			
		||||
        try { 
 | 
			
		||||
         exp.forEachAsync = create(require('rsvp'));
 | 
			
		||||
        } catch(e) {
 | 
			
		||||
          console.warn('forEachAsync needs requires a promise implementation and your environment does not provide one.'
 | 
			
		||||
            + '\nYou may provide your own by calling forEachAsync.create(Promise) with a PromiseA+ implementation'
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      console.warn("This version of node doesn't support promises. Please `npm install --save bluebird` in your project.");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -87,4 +76,4 @@
 | 
			
		||||
  };
 | 
			
		||||
  exports.forEachAsync.create = create;
 | 
			
		||||
 | 
			
		||||
}('undefined' !== typeof exports && exports || new Function('return this')()));
 | 
			
		||||
}('undefined' !== typeof exports && exports || window));
 | 
			
		||||
							
								
								
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "foreachasync",
 | 
			
		||||
  "version": "5.1.3",
 | 
			
		||||
  "lockfileVersion": 1
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								package.json
									
									
									
									
									
								
							@ -1,9 +1,10 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "foreachasync",
 | 
			
		||||
  "version": "5.0.4",
 | 
			
		||||
  "version": "5.1.3",
 | 
			
		||||
  "description": "A node- and browser-ready async (now with promises) counterpart of Array.prototype.forEach",
 | 
			
		||||
  "homepage": "https://github.com/FuturesJS/forEachAsync",
 | 
			
		||||
  "main": "forEachAsync.js",
 | 
			
		||||
  "homepage": "https://git.coolaj86.com/coolaj86/foreachasync.js",
 | 
			
		||||
  "main": "foreachasync.js",
 | 
			
		||||
  "files": [],
 | 
			
		||||
  "directories": {
 | 
			
		||||
    "test": "test"
 | 
			
		||||
  },
 | 
			
		||||
@ -12,7 +13,7 @@
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git://github.com/FuturesJS/forEachAsync.git"
 | 
			
		||||
    "url": "https://git.coolaj86.com/coolaj86/foreachasync.js.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "futuresjs",
 | 
			
		||||
@ -25,14 +26,13 @@
 | 
			
		||||
    "promises",
 | 
			
		||||
    "each"
 | 
			
		||||
  ],
 | 
			
		||||
  "optionalDependencies": {
 | 
			
		||||
    "bluebird": "^2.5.3"
 | 
			
		||||
  "trulyOptionalDependencies": {
 | 
			
		||||
    "bluebird": "^3.5.1"
 | 
			
		||||
  },
 | 
			
		||||
  "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.com/)",
 | 
			
		||||
  "license": "Apache2",
 | 
			
		||||
  "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
 | 
			
		||||
  "license": "(MIT OR Apache-2.0)",
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://github.com/FuturesJS/forEachAsync/issues"
 | 
			
		||||
    "url": "https://git.coolaj86.com/coolaj86/foreachasync.js/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
  }
 | 
			
		||||
  "dependencies": {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,16 +1,14 @@
 | 
			
		||||
(function () {
 | 
			
		||||
  "use strict";
 | 
			
		||||
 | 
			
		||||
  var PromiseA = require('bluebird')
 | 
			
		||||
    , forEachAsync = require('./forEachAsync').forEachAsync
 | 
			
		||||
    , context = {}
 | 
			
		||||
    ;
 | 
			
		||||
  var PromiseA = require('bluebird');
 | 
			
		||||
  var forEachAsync = require('./forEachAsync').forEachAsync;
 | 
			
		||||
  var context = {};
 | 
			
		||||
 | 
			
		||||
  forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) {
 | 
			
		||||
    console.log(i, '/', arr.length, 'began');
 | 
			
		||||
 | 
			
		||||
    var result
 | 
			
		||||
      ;
 | 
			
		||||
    var result;
 | 
			
		||||
 | 
			
		||||
    // test that thisness is applied
 | 
			
		||||
    this[element] = i;
 | 
			
		||||
@ -20,7 +18,7 @@
 | 
			
		||||
      result = PromiseA.resolve();
 | 
			
		||||
    } else {
 | 
			
		||||
      // test asynchronous callbacks
 | 
			
		||||
      result = new Promise(function (resolve/*, reject*/) {
 | 
			
		||||
      result = new PromiseA(function (resolve/*, reject*/) {
 | 
			
		||||
        setTimeout(resolve, element);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,12 @@
 | 
			
		||||
(function () {
 | 
			
		||||
  "use strict";
 | 
			
		||||
 | 
			
		||||
  var forEachAsync = require('./forEachAsync').forEachAsync.create(Promise)
 | 
			
		||||
    , context = {}
 | 
			
		||||
    ;
 | 
			
		||||
  /* globals Promise */
 | 
			
		||||
  var forEachAsync = require('./forEachAsync').forEachAsync.create(Promise);
 | 
			
		||||
  var context = {};
 | 
			
		||||
 | 
			
		||||
  forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) {
 | 
			
		||||
    var p
 | 
			
		||||
      ;
 | 
			
		||||
    var p;
 | 
			
		||||
 | 
			
		||||
    // test that thisness is applied
 | 
			
		||||
    this[element] = i;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user