Skip to content

Commit

Permalink
fix: make methods reenrant
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed May 17, 2022
1 parent d108d3c commit 3d08a97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/one-time-execution-method.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function replaceWithOneTimeExecutionMethod(object, name) {
Object.defineProperty(object, name, {
value: function (...args) {
if (this[transitionState] === undefined) {
// make method reentrant
this[transitionState] = Promise.resolve();

this[transitionState] = func.apply(this, ...args);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/one-time-execution-method-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test("replaceWithOneTimeExecutionMethod parallel", async t => {

replaceWithOneTimeExecutionMethod(MyClass.prototype, "reentrantInitialize");

test.skip("replaceWithOneTimeExecutionMethod reentrant", async t => {
test("replaceWithOneTimeExecutionMethod reentrant", async t => {
const object = new MyClass();

t.is(object.executions, 0);
Expand Down

0 comments on commit 3d08a97

Please sign in to comment.