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

when(resolved:) tuple overloads #1092

Open
wants to merge 3 commits into
base: v7
Choose a base branch
from

Conversation

Skoti
Copy link
Contributor

@Skoti Skoti commented Aug 24, 2019

This PR introduces tuple overloads for when(resolved:) (which make use of Thenable protocol) and additional tuple overloads for when(fulfilled:) up to 9 arguments.
This PR also introduces an associated type R representing the result type in Thenable protocol which improves a return type in when(resolved:) when using Guarantees, so this is now allowed:

let p1 = Promise.value(true)
let p2 = Promise.value(2)
let g1 = Guarantee.value("abc")

when(resolved: p1, p2, g1).done { r1, r2, r3 in
    // r1 is Result<Bool>, r2 is Result<Int>, r3 is String
}

In the future it might be worth considering changing the pipe declaration to use R instead of Result<T>, this would however impact all the other operators so I didn't want to introduce such a big change in this PR.

@mxcl
Copy link
Owner

mxcl commented Sep 1, 2019

Seems cool. Can we make tests pass?

@Skoti Skoti force-pushed the feature/when_tuples_and_mixing branch from 6b0f972 to d13d220 Compare September 2, 2019 05:24
@Skoti
Copy link
Contributor Author

Skoti commented Sep 2, 2019

Done :)

@Skoti
Copy link
Contributor Author

Skoti commented Oct 8, 2019

still interested in merging? :)

@IgnusG
Copy link

IgnusG commented Dec 6, 2019

This would be great - is there a timeline on this or is PMK7 incompatible/already implementing this?

Tests/CorePromise/WhenResolvedTests.swift Outdated Show resolved Hide resolved
Tests/CorePromise/WhenTests.swift Outdated Show resolved Hide resolved
@mxcl mxcl force-pushed the master branch 15 times, most recently from 9e44117 to e6e8f32 Compare May 26, 2021 01:36
@mxcl
Copy link
Owner

mxcl commented Jun 2, 2021

If we can base this onto v7 we can get it in.

@Skoti
Copy link
Contributor Author

Skoti commented Jun 2, 2021

If we can base this onto v7 we can get it in.

Ok great! Give me some time :)

@Skoti Skoti force-pushed the feature/when_tuples_and_mixing branch from d13d220 to b433e10 Compare June 5, 2021 20:26
@Skoti
Copy link
Contributor Author

Skoti commented Jun 5, 2021

  1. I've rebased this PR and added tuple arity functions for cancellable thenables up to 9 arguments.
  2. I've also improved when(resolved:) for array and when(fulfilled:) with generator to work for any CancellableThenable and not only CancellablePromise.
  3. I've added when(resolved:) with generator.
  4. I've renamed cancellableWhen functions to just when to match the naming convention.
  5. In order to keep the tests more readable and clean I've added a shared TestError and TestCancelError types.

@mxcl
Copy link
Owner

mxcl commented Jun 7, 2021

Merge conflicts.

@Skoti Skoti changed the base branch from master to v7 June 7, 2021 15:05
@Skoti
Copy link
Contributor Author

Skoti commented Jun 7, 2021

The PR was still set to merge to master. I've just changed the base branch to v7.

@mxcl
Copy link
Owner

mxcl commented Jun 7, 2021

CI did not run (GitHub Actions bug perhaps) we need that to verify that the changes do not cause ambiguity. Even then I am concerned about the change of cancellableWhen to when being ambiguous to the compiler.

I'd like to see this PR without all the infrastructure changes since it bloats it substantially.

@Skoti
Copy link
Contributor Author

Skoti commented Jun 11, 2021

The ambiguity usages were due to the variadic when functions.

I agree this is better, but breaking API is not allowed, API breakage can only happen for major version bumps, so this may have to be a v7 PR if we cannot solve it.

But we agreed that it is better to have tuple arity functions, as variadic is easy to fix as you just add [ and ] around the arguments. From the calling point of view it is almost no difference. Not sure what is more convenient with variadic arguments that an array couldn't handle.

By infrastructure you mean adding a common module?

@Skoti Skoti force-pushed the feature/when_tuples_and_mixing branch from b433e10 to 4acf52e Compare July 14, 2021 16:50
@Skoti
Copy link
Contributor Author

Skoti commented Jul 14, 2021

@mxcl I got rid of the infrastructure changes.

@Skoti Skoti force-pushed the feature/when_tuples_and_mixing branch from 4acf52e to 51c223c Compare July 16, 2021 12:26
mxcl and others added 3 commits July 23, 2021 08:42
Ideally I'd fix it, but I have no idea what it is testing even. Yay.
…r thenables and cancellable thenables

add an associated type R representing the result type in Thenable which improves when(resolved:) return type
@mxcl mxcl force-pushed the feature/when_tuples_and_mixing branch from 51c223c to 7a65168 Compare July 23, 2021 13:00
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.

None yet

3 participants