feat: support get/cancel/remove tasks under specific condition given by a function #4
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.
昨天我在AList的主仓库下面提出了#7398这个issue,它是关于让GENERAL用户也能看到和控制由自己创建的离线下载/上传/复制任务的。今天我尝试了在尽可能不将需求侵入到这个库里的条件下实现这个需求,为此我在AList主项目中创建了一个新的Task结构体并内嵌了tache.Base结构体,在这个新的结构体中添加Creator成员。但是要实现从Manager中取出具有特定Creator的Task,就需要一个类似GetByState的GetByCreator函数(其实也可以先用GetAll得到所有Task,再从中筛选,但那样的话会多创建一个切片,有效率问题而且不够优雅)。因此我实现了GetByCondition、CancelByCondition、RemoveByCondition三个Manager的成员函数,它们可以根据由调用者给出的,匿名函数形式的条件,来得到/停止/删除部分Manager中的Task,这样以后所有基于此库开发,且有对Task进行扩展的需求的情况,就能用这三个接口实现依赖倒置。