Skip to content

Commit

Permalink
Improve use of return/throw methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jan 31, 2024
1 parent 4fab6c6 commit 2d3a87e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
3 changes: 0 additions & 3 deletions src/txn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ void TxnWrap::removeFromEnvWrap() {
if (this->ew) {
if (this->ew->currentWriteTxn == this) {
this->ew->currentWriteTxn = this->parentTw;
if (this->parentTw) {
fprintf(stderr, "ending child transaction\n");
}
}
else {
auto it = std::find(ew->readTxns.begin(), ew->readTxns.end(), this);
Expand Down
49 changes: 27 additions & 22 deletions util/RangeIterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const DONE = {
value: null,
done: true,
}
const RETURN_DONE = { // we allow this one to be mutated
value: null,
done: true,
};
if (!Symbol.asyncIterator) {
Symbol.asyncIterator = Symbol.for('Symbol.asyncIterator');
}
Expand Down Expand Up @@ -33,11 +37,10 @@ export class RangeIterable {
iteratorResult = iterator.next();
if (iteratorResult.then) {
if (!async) {
throw new Error('Can not synchronously iterate with asynchronous values');
this.throw(new Error('Can not synchronously iterate with asynchronous values'));
}
return iteratorResult.then(iteratorResult => this.next(iteratorResult), (error) => {
this.return();
throw error;
this.throw(error);
});
}
}
Expand All @@ -55,8 +58,7 @@ export class RangeIterable {
{
value: result
}, (error) => {
this.return();
throw error;
this.throw(error);
});
}
} while(result === SKIP);
Expand All @@ -67,23 +69,21 @@ export class RangeIterable {
value: result
};
} catch(error) {
this.return();
throw error;
this.throw(error);
}
},
return() {
return(value) {
if (!this.done) {
RETURN_DONE.value = value;
this.done = true;
if (iterable.onDone) iterable.onDone();
return iterator.return();
iterator.return();
}
return RETURN_DONE;
},
throw() {
if (!this.done) {
this.done = true;
if (iterable.onDone) iterable.onDone();
return iterator.throw();
}
throw(error) {
this.return();
throw error;
}
};
};
Expand Down Expand Up @@ -134,8 +134,7 @@ export class RangeIterable {
} else if (result.done) concatIterable.onDone();
}
} catch (error) {
this.return();
throw error;
this.throw(error);
}
} else {
if (concatIterable.onDone) concatIterable.onDone();
Expand All @@ -161,12 +160,18 @@ export class RangeIterable {
}
},
return() {
if (concatIterable.onDone) concatIterable.onDone();
return iterator.return();
if (!this.done) {
RETURN_DONE.value = value;
this.done = true;
if (concatIterable.onDone) concatIterable.onDone();
iterator.return();
}
return RETURN_DONE;

},
throw() {
if (concatIterable.onDone) concatIterable.onDone();
return iterator.throw();
throw(error) {
this.return();
throw error;
}
};
};
Expand Down

0 comments on commit 2d3a87e

Please sign in to comment.