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

Feature/allSettled(), any(), race() #25

Merged
merged 9 commits into from
Nov 14, 2024
Merged

Conversation

chrisdp
Copy link
Contributor

@chrisdp chrisdp commented Nov 8, 2024

No description provided.

@chrisdp chrisdp added the enhancement New feature or request label Nov 8, 2024
@chrisdp chrisdp changed the title Feature/all settled any race Feature/allSettled(), any(), race() Nov 8, 2024
@jtuckerfubo
Copy link
Collaborator

jtuckerfubo commented Nov 8, 2024

this gives the right answer, but takes 70s to finish
fwiw, the time to finish doesn't make sense to me...

@only
	@async(5000)
	@it("justin test")
	sub _()
		p0 = promises.onThen(sleepPromise(0), function(res, ctx) : return ctx : end function, 0)
		p1 = promises.onThen(sleepPromise(1), function(res, ctx) : return ctx : end function, 1)
		p2 = promises.onThen(sleepPromise(2), function(res, ctx) : return ctx : end function, 2)
		p3 = promises.onThen(sleepPromise(3), function(res, ctx) : return ctx : end function, 3)
		p4 = promises.onThen(sleepPromise(4), function(res, ctx) : return ctx : end function, 4)
		all = [p4, p3, p2, p1, p0]

		promises.onThen(promises.race(all), sub(result)
			? `result=${result}`
			m.testSuite.assertEqual(result, 0)
			m.testSuite.done()
		end sub)
	end sub

note: the issue here is that my understanding of "race" is that it finishes when the first of a collection of promises finishes (asynchronously), so the expectation is that the the unit test finishes right away. Instead this took a lot of time, possibly 0s + 1s+ 2s + 3s + 4s + 60s (which is the suite timeout) = 70s. Oddly, when I shift the order of the input promises around, the test seams to finish right away. Also note that this is true for rejecting promises as well (which is what I expect).

src/source/promises.bs Outdated Show resolved Hide resolved
src/source/promises.bs Outdated Show resolved Hide resolved
src/source/promises.bs Outdated Show resolved Hide resolved
src/source/promises.bs Outdated Show resolved Hide resolved
src/source/promises.bs Outdated Show resolved Hide resolved
src/source/promises.bs Outdated Show resolved Hide resolved
@chrisdp chrisdp merged commit fc05271 into master Nov 14, 2024
1 of 2 checks passed
@chrisdp chrisdp deleted the feature/all-settled_any_race branch November 14, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants