vapor / async-kit

Sugary extensions for the SwiftNIO library
MIT License
71 stars 25 forks source link

.andAllSync #18

Closed tanner0101 closed 4 years ago

tanner0101 commented 5 years ago

Would something like this be useful to add?

extension EventLoopFuture {
    public static func andAllSync(
        _ futures: [() -> EventLoopFuture<Void>],
        eventLoop: EventLoop
    ) -> EventLoopFuture<Void> {
        ...
    }
}

The difference to .andAll is that each future is not started until the previous one completes. This is useful for things like database migrations where you must not start the next task until the previous is completed.

Mordil commented 5 years ago

Is this valid Swift?

public static func andAllSync(
    _ futures: [@autoclosure () -> EventLoopFuture<Void>],
    eventLoop: EventLoop
) -> EventLoopFuture<Void> { }
tanner0101 commented 5 years ago

Looks like no. Bummer because I was thinking about that, too.

screen shot 2019-01-31 at 1 53 20 pm

Mordil commented 5 years ago

Hm. Sounds like an idea to float on the forums...

Overall - this is good. Just some bikeshedding over parameter name and method name.

I'm still trying to resolve what to have the methods be named in SwiftNIO itself with the type of extensions I've been writing for it.

tanner0101 commented 5 years ago

@Mordil I guess this should wait until the bikeshedding is complete with your proposal, then we can make sure this one follows suit with naming.

Mordil commented 5 years ago

If you want to jump in and share your thoughts I brought it up on this thread: https://github.com/apple/swift-nio/issues/184#issuecomment-457649370

Mordil commented 5 years ago

@tanner0101 It looks like the proposed names of andAll{Succeed | Complete} and whenAll{Succeed | Complete} are being accepted in SwiftNIO

tanner0101 commented 4 years ago

EventLoopFutureQueue can now be used to implement this behavior 👍