-
Notifications
You must be signed in to change notification settings - Fork 1k
[@lit-labs/task] Refines when tasks are run #2336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes #2323 and #2317. * Tasks with no arguments now run by default if they are not pending and not signaling a status change. * Can specify a `canRun` method . It receives arguments of a default `canRun()` function, the task's status, and the values of the task's arguments. * Adds option to specify task arguments via a config object and this is how canRun is used {task, arguments?, canRun?} * Changes Task "dependencies" to "arguments."
🦋 Changeset detectedLatest commit: 298f31a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
|
|
I still like the idea that a Task with no args function is no auto-run at all, and a task with an empty args array is auto-run because there's no args to dirty-check: new Task(host, fn); // not auto-run
new Task(host, fn, () => []); // auto-run
Is this how we'd have to do it with class MyElement extends LitElement {
private _task = new Task(this, {task: async() => {...}, canRun: () => this._canRunTask});
private @state _canRunTask = false;
private async _runTask() {
this._canRunTask = true;
this._task.runTask();
await this._task.taskComplete;
this._canRunTask = false;
}
private _onRunButtonClick() {
this._runTask();
}
}I'd like to see something more like: class MyElement extends LitElement {
private _task = new Task(this, async() => {...});
private _onRunButtonClick() {
this._task.run();
}
} |
|
Thinking about this again, I think probably
|
canRun for customization.canRun for customization.
* tasks run whenever args change * disable this by setting `autoRun` to false, either in the task config or later on the task * call `run(args?)` explicitly to force the task to run
canRun for customization.| this._task = task; | ||
| this._getDependencies = getDependencies; | ||
| this._getArgs = args; | ||
| this.taskComplete = new Promise((res, rej) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this change for manual run tasks so that it's a resolved promise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering what await task.taskComplete should do for a manually run task? The task is idle, but it's not necessarily ever going to run. In some ways it seems like a task that has completed some times, and might or might not run again, and in that case taskComplete would be a resolved promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's handle this as a follow on. Filed #2347.
Fixes #2323 and #2317.
autoRuntofalse. This can be done via the task config or by setting the property on the task itself.run()(optionally specifying task arguments) to explicitly run the task.