Skip to content

Commit

Permalink
Add missing await in task.ts (#3847)
Browse files Browse the repository at this point in the history
* Add missing await in task.ts

* Changeset

* Add a test that performTask awaits.
  • Loading branch information
rictic committed Apr 28, 2023
1 parent cd75977 commit b362585
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/friendly-grapes-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/task': patch
---

Add a missing await in performTask
2 changes: 1 addition & 1 deletion packages/labs/task/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class Task<
protected async performTask() {
const args = this._getArgs?.();
if (this.shouldRun(args)) {
this.run(args);
await this.run(args);
}
}

Expand Down
19 changes: 19 additions & 0 deletions packages/labs/task/src/test/task_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,23 @@ suite('Task', () => {

assert.equal(el.taskObservedValue, 'bar');
});

test('performTask waits on the task', async () => {
const el = getTestElement({
args: () => [el.a],
});
await renderElement(el);
let taskComplete = false;
(async () => {
el.a = 'z';
// @ts-expect-error: We're testing the behavior of a protected method
await el.task.performTask();
taskComplete = true;
})();
await tasksUpdateComplete();
assert.isFalse(taskComplete);
el.resolveTask();
await tasksUpdateComplete();
assert.isTrue(taskComplete);
});
});

0 comments on commit b362585

Please sign in to comment.