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 operations #91

Merged
merged 15 commits into from
Nov 20, 2023
Merged

Async operations #91

merged 15 commits into from
Nov 20, 2023

Conversation

smikhalevski
Copy link
Owner

@smikhalevski smikhalevski commented Oct 26, 2023

  • Renamed use to addOperation and added addAsyncOperation, so now async operations can be added to any shape. For example, this allowed to enable support of async shapes in ArrayShape.includes check:
const shape1 = d.string().checkAsync(async () => );

const shape2 = d.array().includes(shape1);

shape2.isAsync;
// ⮕ true
  • Added checkAsync, refineAsync, and alterAsync;

  • Removed async to sync auto downgrade optimization, so if parseAsync is called on a sync shape it would use the async path instead of wrapping a sync path in a promise.

New semantics

_applyOperations now returns a promise if there are async operations.

If the shape overrides only _apply and doesn't override _applyAsync then it's only safe
to call this method as the last statement in _apply. Otherwise, it may return an unexpected promise.

If the shape overrides both _apply and _applyAsync then this method would always
synchronously return a Result inside _apply.

@smikhalevski smikhalevski merged commit 44cc1b7 into next Nov 20, 2023
4 checks passed
@smikhalevski smikhalevski deleted the async-operations branch November 20, 2023 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant