feat: Added support for lazy variables evaluation #1231
+221
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request supports delayed evaluation of dynamic variables, adding a
lazy
option to thevars[]
schema that makes the execution of global dynamic variable shell commands happen only when necessary.What this feature
In the current go-task, global dynamic variables always execute their commands. Therefore, with a Taskfile.yaml like the following, running
task depend-on-only-fast-var
always causes a 3-second wait due toSLOW_VAR
.With the functionality added in this PR, dynamic variable evaluations can be delayed until necessary. This means that with a Taskfile.yaml like the following,
task depend-on-only-fast-var
can be executed immediately.How
Instead of passing strings as variables to the text/template, a structure that implements the
Stringer
interface is passed, which executes the command and uses the result as a dynamic variable the first time it's called. That result is then cached in the structure, ensuring that the same command is never executed twice. The Singleflight library guarantees that it will be executed only once even if called concurrently.Compatibility with this PR
This PR does not break compatibility. Dynamic variables that are not marked as
lazy: true
will continue to operate as before.