Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Replace Collection<Future>.flatten with Future.reduce? #154

Open
MrMage opened this issue May 27, 2018 · 8 comments
Open

Replace Collection<Future>.flatten with Future.reduce? #154

MrMage opened this issue May 27, 2018 · 8 comments
Assignees

Comments

@MrMage
Copy link
Contributor

MrMage commented May 27, 2018

At the moment we are implementing `flatten ourself in

public func flatten(on worker: Worker) -> Future<[Element.Expectation]> {
.

We could investigate whether we could replace that with an almost-trivial call to https://github.com/apple/swift-nio/blob/82a6e4d8215660005127547106aa8cf10817cb78/Sources/NIO/EventLoopFuture.swift#L915.

@tanner0101 tanner0101 self-assigned this May 30, 2018
@tanner0101
Copy link
Member

As long as we can ensure the ordering remains the same as the current method, I'd be happy to do this 👍

@MrMage
Copy link
Contributor Author

MrMage commented May 30, 2018

I think it should stay the same. Actually, I thought we had a test that flatten() created an array with the results in the correct order, but can't find it right now :-/

@jdmcd
Copy link
Member

jdmcd commented May 30, 2018

@MrMage looks like the second test in this file checks for the correct order https://github.com/vapor/core/blob/master/Tests/AsyncTests/AsyncTests.swift

@MrMage
Copy link
Contributor Author

MrMage commented May 30, 2018

Good find! However, I think to properly test this the order of succeeding would need to be reversed:

    b.succeed(result: "b")
    a.succeed(result: "a")

@jdmcd
Copy link
Member

jdmcd commented May 30, 2018

My understanding is that flatten can succeed futures in any order as long as they are returned in the correct order. If I’m correct in that assumption, I think the test does what it needs to (it could also probably test succeeding in a different order and getting the same array result)

@MrMage
Copy link
Contributor Author

MrMage commented May 30, 2018

At the moment, the test only ensures the correct order if the input futures already succeed in the same order, which should be trivial. Swapping the succeed calla would actially test that the final order is still correct, even if the futures succeed in the "wrong" order.

@jdmcd
Copy link
Member

jdmcd commented May 30, 2018

I see. Yeah that should be added

@MrMage
Copy link
Contributor Author

MrMage commented Apr 1, 2019

Closing this because of #199.

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

No branches or pull requests

3 participants