Skip to content

Commit

Permalink
refactor(collections): moves series and parallel to collections; refa…
Browse files Browse the repository at this point in the history
…ctor source and tests to match usage of newest api
  • Loading branch information
rafamel committed Oct 31, 2019
1 parent 3da1ac2 commit 84046fd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/collections/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as parallel } from './parallel';
export { default as series } from './series';
4 changes: 2 additions & 2 deletions src/parallel.ts → src/collections/parallel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import deferred from './create/deferred';
import { Promist } from '~/classes';

export function map<T>(
arr: Array<Promise<T> | T>,
Expand Down Expand Up @@ -37,7 +37,7 @@ export function reduce<T>(
return Promise.all(arr).then((resArr) => {
return resArr.slice(1).reduce(
(acc, x, i) => {
const p = deferred();
const p = new Promist();
acc.then((val) => p.resolve(val)).catch((err) => p.reject(err));
return fn(p, x, i + 1, resArr);
},
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions test/parallel.test.ts → test/collections/parallel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parallel from '~/parallel';
import lazy from '~/create/lazy';
import parallel from '~/collections/parallel';
import { LazyPromist } from '~/classes';

const createArr = (arr: number[] = [1, 2, 3, 4]): Array<Promise<number>> => {
return arr.map((x) => Promise.resolve(x));
Expand All @@ -11,7 +11,9 @@ const createDelayedArr = (
return Array(50)
.fill(0)
.map((_, i) => {
return lazy((resolve) => setTimeout(() => resolve(i), ms * (n - i)));
return new LazyPromist((resolve) => {
setTimeout(() => resolve(i), ms * (n - i));
});
});
};

Expand Down
8 changes: 5 additions & 3 deletions test/series.test.ts → test/collections/series.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import series from '~/series';
import lazy from '~/create/lazy';
import series from '~/collections/series';
import { LazyPromist } from '~/classes';

const createArr = (arr: number[] = [1, 2, 3, 4]): Array<Promise<number>> => {
return arr.map((x) => Promise.resolve(x));
Expand All @@ -11,7 +11,9 @@ const createDelayedArr = (
return Array(50)
.fill(0)
.map((_, i) => {
return lazy((resolve) => setTimeout(() => resolve(i), ms * (n - i)));
return new LazyPromist((resolve) => {
setTimeout(() => resolve(i), ms * (n - i));
});
});
};

Expand Down

0 comments on commit 84046fd

Please sign in to comment.