Skip to content

Commit

Permalink
Put a 'return' statement in front of every 'resolve()' and 'reject()'…
Browse files Browse the repository at this point in the history
… inside of Promises to avoid bugs
  • Loading branch information
loehnertz committed Feb 8, 2018
1 parent 23d48b9 commit 67a5ef5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions app/ccurl-interface.js
Expand Up @@ -39,10 +39,10 @@ class CcurlInterface {
this.checkInput();
this.loopTrytes(this.index);
} catch (err) {
reject(err);
return reject(err);
}
setInterval(() => {
if (this.finishedPoW) resolve(this.finalBundleTrytes.reverse());
if (this.finishedPoW) return resolve(this.finalBundleTrytes.reverse());
}, 1234);
});
};
Expand Down Expand Up @@ -103,11 +103,11 @@ class CcurlInterface {

let newTrytes = this.iota.utils.transactionTrytes(txObject);
this.libccurl.ccurl_pow.async(newTrytes, this.minWeightMagnitude, (err, returnedTrytes) => {
if (err) reject(err);
if (err) return reject(err);

// Check that the PoW actually succeeded
if (!returnedTrytes) {
reject(new TanglestashCustomErrors.LibccurlInterruptionError('PoW failed!'));
return reject(new TanglestashCustomErrors.LibccurlInterruptionError('PoW failed!'));
} else {
let newTxObject = this.iota.utils.transactionObject(returnedTrytes);

Expand All @@ -116,7 +116,7 @@ class CcurlInterface {
// Push the returned trytes to the bundle array
this.finalBundleTrytes.push(returnedTrytes);

resolve();
return resolve();
}
});
});
Expand Down
38 changes: 19 additions & 19 deletions app/tanglestash.js
Expand Up @@ -158,9 +158,9 @@ class Tanglestash {
if (this.successfulChunks === this.totalChunkAmount) {
clearInterval(finishedCheck);
try {
resolve(this.chunkBundle);
return resolve(this.chunkBundle);
} catch (err) {
reject(err);
return reject(err);
}
} else {
for (let chunk in this.failedChunks) {
Expand Down Expand Up @@ -225,20 +225,20 @@ class Tanglestash {
if (err) {
switch (err.message) {
case 'Invalid inputs provided.':
reject(new TanglestashCustomErrors.IncorrectTransactionHashError(err.message));
return reject(new TanglestashCustomErrors.IncorrectTransactionHashError(err.message));
break;
case 'Invalid Bundle provided.':
reject(new TanglestashCustomErrors.NodeOutdatedError(err.message));
return reject(new TanglestashCustomErrors.NodeOutdatedError(err.message));
break;
case 'Invalid tail transaction supplied.':
reject(new TanglestashCustomErrors.MalformedPersistedDataError(err.message));
return reject(new TanglestashCustomErrors.MalformedPersistedDataError(err.message));
break;
default:
reject(new Error(err.message));
return reject(new Error(err.message));
break;
}
}
resolve(transactionBundle);
return resolve(transactionBundle);
});
});
}
Expand Down Expand Up @@ -387,12 +387,12 @@ class Tanglestash {
getParentTransactions() {
return new Promise((resolve, reject) => {
this.iota.api.getTransactionsToApprove(this.IotaTransactionDepth, null, (err, transactions) => {
if (err) reject(err);
if (err) return reject(err);

if (!transactions) {
reject(new TanglestashCustomErrors.NodeCouldNotProvideTransactionsToApproveError());
return reject(new TanglestashCustomErrors.NodeCouldNotProvideTransactionsToApproveError());
} else {
resolve({
return resolve({
trunkTransaction: transactions.trunkTransaction,
branchTransaction: transactions.branchTransaction,
});
Expand All @@ -419,12 +419,12 @@ class Tanglestash {
(err, bundle) => {
if (err || !bundle) {
if (err.message.includes('failed consistency check')) {
reject(new TanglestashCustomErrors.NodeOutdatedError(err.message));
return reject(new TanglestashCustomErrors.NodeOutdatedError(err.message));
} else {
reject(new Error(err.message || 'No correct bundle was returned'));
return reject(new Error(err.message || 'No correct bundle was returned'));
}
}
resolve(bundle);
return resolve(bundle);
});
});
}
Expand All @@ -442,9 +442,9 @@ class Tanglestash {
this.iota,
this.libccurl
).performPoW().then((result) => {
resolve(result);
return resolve(result);
}).catch((err) => {
reject(err);
return reject(err);
});
});
}
Expand All @@ -455,8 +455,8 @@ class Tanglestash {
broadcastTransaction(transactionTrytes) {
return new Promise((resolve, reject) => {
this.iota.api.storeAndBroadcast(transactionTrytes, (err, output) => {
if (err) reject(err);
resolve(this.iota.utils.transactionObject(transactionTrytes[0]));
if (err) return reject(err);
return resolve(this.iota.utils.transactionObject(transactionTrytes[0]));
});
});
}
Expand Down Expand Up @@ -526,8 +526,8 @@ class Tanglestash {
getNewIotaAddress() {
return new Promise((resolve, reject) => {
this.iota.api.getNewAddress(this.seed, (err, address) => {
if (err) reject(new Error(err.message));
resolve(address);
if (err) return reject(new Error(err.message));
return resolve(address);
});
});
}
Expand Down

0 comments on commit 67a5ef5

Please sign in to comment.