Skip to content

Commit 01dfef9

Browse files
tiny fix in the source code and test mode.
1 parent 576211d commit 01dfef9

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

src/index.mjs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ import { objType } from './utils/lib.mjs';
5151
* console.log(item);
5252
* result(); // move to next
5353
* }).then(res => console.log(res));
54-
*
54+
*
5555
* @example
5656
* const input = {
5757
* data: [1, 2, 3],
5858
* };
59-
*
59+
*
6060
* forPromise(input, (item, result, error, extraFn) => {
6161
* if (item === 2) return result({ break: true });
6262
* result();
@@ -160,42 +160,43 @@ export default function forPromise(obj, callback) {
160160
item_to_edit.count > 0))
161161
) {
162162
// Normal Result
163-
if (!isExtra)
163+
if (!isExtra) {
164164
if (!extra.enabled) resolve(items);
165-
// Extra Result
166-
else {
167-
// Check Extra Exist
168-
if (extra.list[extraIndex]) {
169-
// Complete Check
170-
extra.list[extraIndex].complete = true;
171-
172-
// Check List
173-
let confirmation_checked = true;
174-
175-
// Detect Progress
176-
for (const item in extra.list) {
177-
if (!extra.list[item].complete) {
178-
confirmation_checked = false;
179-
break;
180-
}
165+
}
166+
// Extra Result
167+
else {
168+
// Check Extra Exist
169+
if (extra.list[extraIndex]) {
170+
// Complete Check
171+
extra.list[extraIndex].complete = true;
172+
173+
// Check List
174+
let confirmation_checked = true;
175+
176+
// Detect Progress
177+
for (const item in extra.list) {
178+
if (!extra.list[item].complete) {
179+
confirmation_checked = false;
180+
break;
181181
}
182+
}
182183

183-
// Complete
184-
if (confirmation_checked) {
185-
// Add Extra Info
186-
items.extra = extra.list;
184+
// Complete
185+
if (confirmation_checked) {
186+
// Add Extra Info
187+
items.extra = extra.list;
187188

188-
// Resolve
189-
resolve(items);
190-
}
189+
// Resolve
190+
resolve(items);
191191
}
192+
}
192193

193-
// Nope
194-
else {
195-
items.error = true;
196-
reject(new Error('forAwait Extra Index not found.'));
197-
}
194+
// Nope
195+
else {
196+
items.error = true;
197+
reject(new Error(`forAwait Extra Index ${extraIndex} not found.`));
198198
}
199+
}
199200
}
200201
}
201202
};
@@ -364,9 +365,7 @@ export default function forPromise(obj, callback) {
364365
// Run Extra
365366
run: function (callback) {
366367
// Run For
367-
if (!items.error && !items.forceBreak) {
368-
runFor(callback, true, index, new_extra);
369-
}
368+
if (!items.error && !items.forceBreak) runFor(callback, true, index, new_extra);
370369
},
371370
};
372371
}

test/index.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'node:url';
44

5-
import forPromise from '../index.mjs';
5+
import forPromise from '../src/index.mjs';
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url));
88

@@ -83,10 +83,10 @@ const tiny_test = async function () {
8383
const extraForAwait = extra({ data: data2 });
8484

8585
// Execute the extra For Script
86-
extraForAwait.run(function (index2, fn) {
86+
extraForAwait.run(function (index2, fn2) {
8787
// Show Index
8888
console.log(`For (Extra): '${index2}'`);
89-
fn();
89+
fn2();
9090
});
9191

9292
console.groupEnd();
@@ -115,7 +115,7 @@ const tiny_test = async function () {
115115
},
116116
function (item, fn, fn_error) {
117117
// Wait Script
118-
fs.readdir(path.join(__dirname, '../files'), (err, files) => {
118+
fs.readdir(path.join(__dirname, '../src'), (err, files) => {
119119
// Success! The "fn()" will say that the execution of this script has ended.
120120
if (!err) {
121121
console.log(`Force Break used to read this data: ${item}`);
@@ -128,9 +128,6 @@ const tiny_test = async function () {
128128
fn_error(err);
129129
}
130130
});
131-
132-
// Force Complete
133-
fn({ break: true, dontSendResult: true });
134131
},
135132
);
136133

0 commit comments

Comments
 (0)