Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Conversation

@jtakalai
Copy link
Contributor

@jtakalai jtakalai commented May 3, 2021

also fix comments

@jtakalai jtakalai requested a review from timoxley May 3, 2021 08:22
Copy link
Contributor

@timoxley timoxley left a comment

Choose a reason for hiding this comment

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

Great change, especially if condition is async.

Could add a test?

})
}

// condition could as well return any instead of boolean, could be convenient sometimes if waiting until a value is returned. Maybe change if such use case emerges.
Copy link
Contributor

Choose a reason for hiding this comment

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

boolean is perfectly fine IMO.
any doesn't communicate that we're expecting a truthy or falsey result, and in the worst case someone just needs to do return !!value instead of return value

Also note line length too long.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh I see, you mean it could return the first/last truthy result of calling condition()… interesting.

Probably don't want any for that, instead you'd infer the type from condition, something like:

async function until<T>(condition: MaybeAsync<() => T>, ): Promise<T> => {

}

wasDone = await Promise.resolve().then(condition) // eslint-disable-line no-await-in-loop
}
return condition()
return wasDone
Copy link
Contributor

Choose a reason for hiding this comment

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

This can never return false anyway right? it'll always either return true or throw with timeout

@timoxley timoxley force-pushed the improve-until-util branch from 5e01a4d to 4d328cb Compare May 11, 2021 17:29
@timoxley timoxley merged commit 3123fad into master May 17, 2021
@timoxley timoxley deleted the improve-until-util branch May 17, 2021 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants