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

feat(async/unstable): add waitFor function to wait for condition to be true (#6213) #6230

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

acrodrig
Copy link

@acrodrig acrodrig commented Dec 4, 2024

Submitting PR to contribute waitFor function (see #6213). Fixed small type in delay tests as well.

@acrodrig acrodrig requested a review from kt3k as a code owner December 4, 2024 00:44
@CLAassistant
Copy link

CLAassistant commented Dec 4, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the async label Dec 4, 2024
async/unstable_wait_for.ts Outdated Show resolved Hide resolved

Deno.test("waitFor() throws DOMException on timeout", async () => {
let flag = false;
setTimeout(() => flag = true, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timer needs to be cleared at the end of the test case to avoid op leak error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, makes sense. I do not know why I did not get the leak when running locally.

"Signal timed out.",
);
assertAlmostEquals(Date.now() - start, 100, 10);
assertEquals(error.name, "TimeoutError");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.52%. Comparing base (b1b8279) to head (32764c1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6230   +/-   ##
=======================================
  Coverage   96.52%   96.52%           
=======================================
  Files         534      535    +1     
  Lines       40976    40996   +20     
  Branches     6134     6135    +1     
=======================================
+ Hits        39551    39573   +22     
+ Misses       1383     1381    -2     
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

kt3k

This comment was marked as outdated.

@kt3k kt3k dismissed their stale review December 5, 2024 06:04

retract

@kt3k
Copy link
Member

kt3k commented Dec 5, 2024

I just remembered another rule about designing this type of function.

We tend to put the function-type argument at the last of parameters. The examples are Deno.serve, Deno.test, Deno.addSignalListener.

(It is noted in our style guide)

Note: When one of the arguments is a function, you can adjust the order flexibly. See examples like Deno.serve, Deno.test, Deno.addSignalListener. See also this post.

What do you think about changing this to waitFor(timeout, [options,] predicate)? (We need to use type overload to achieve optional 2nd argument).

@acrodrig
Copy link
Author

acrodrig commented Dec 9, 2024

What do you think about changing this to waitFor(timeout, [options,] predicate)? (We need to use type overload to achieve optional 2nd argument).

Sure, makes sense, let me give it a try. I was following the deadline layout which has the Promise as the first argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants