Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
This repository was archived by the owner on May 26, 2025. It is now read-only.

async/await support #2

@bartoszlenar

Description

@bartoszlenar

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestwontfixThis will not be worked on

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions