Skip to content
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

async/await support #2

Closed
bartoszlenar opened this issue Jun 11, 2020 · 2 comments
Closed

async/await support #2

bartoszlenar opened this issue Jun 11, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@bartoszlenar
Copy link
Owner

Feature description

  • Async version of Validate method.
  • Validation is fast enough that I don't believe we need async/await just for sake of having it.
    • Task & thread orchestration would probably take more time than the validation itself.
  • However the async version could be useful when validation tries to handle large collections.

Feature in action

var validator = Validator.Factory.Create(specification, settings => settings
    .WithTaskScheduler(taskScheduler)
)
Specification<object[]> specification = s => s
    .AsCollection(itemSpecification)
    .WithAsyncStrategy(); // will use some default strategy
 // will use the async version only if more than 10k items, validating 100 items in a single task:

Specification<object[]> specification = s => s
    .AsCollection(itemSpecification)
    .WithAsyncStrategy(bulkSize: 100, minCount: 10000);
var result1 = validator.Validate(hugeCollection); // under the hood it triggers async collection validation anyway

var result2 = await validator.Validate(hugeCollection); // same as above, but bubbles up the task?

Feature details

  • Async strategy would be used for collections only (parameter command that affects AsCollection).
  • Task orchestration done with task scheduler set in the settings.
  • ValidationContext would need to be created for each bulk and at the end - all the contexts from all of the bulks would be merged into the master one.
    • At the same time, it would be nice that the original ValidationContext continue with the regular validation in other places.
@bartoszlenar bartoszlenar added the enhancement New feature or request label Jun 11, 2020
@bartoszlenar bartoszlenar self-assigned this Jun 11, 2020
@bartoszlenar
Copy link
Owner Author

After a lot of offline discussions, I decided to postpone it a little bit. In the vast majority of cases, async/await support is not needed. There are only two justifications for that:

  1. The predicates are awaitable

And Validot doesn't support this approach either now and in the foreseeable future. The validation logic should be quick and straightforward (or at least static) without calling external services or querying remote databases.

In this case, Validot follows a different path than FluentValidation.

  1. Large collections.

This is a valid case, described in this issue's description. However, it's a low priority matter.

@bartoszlenar
Copy link
Owner Author

I'm closing this down. Validot will not be supporting awaitable predicates as rules.

Large collections are a separate issue and I've heard user voices encouraging me to address it... but I don't think that anything similar to WithAsyncStrategy is the solution.

Most probably it will be handled with a separate, dedicated validator. Imagine something more like:

var collectionValidator = ValidatorFactory.CreateForCollections(specification);

var results = await collectionsValidator.Validate(largeCollection);

@bartoszlenar bartoszlenar added the wontfix This will not be worked on label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant