Thomvis / BrightFutures

Write great asynchronous code in Swift using futures and promises
MIT License
1.9k stars 184 forks source link

Chain AsyncType.delay() sequentially rather than in parallel #139

Closed peyton closed 8 years ago

peyton commented 8 years ago

Hey, it was surprising that delay() operated in parallel, eg

let t0 = CACurrentMediaTime()
future { return }
    .delay(1)
    .andThen { _ in print("\(CACurrentMediaTime() - t0) sec" }
    .delay(1)
    .andThen { _ in print("\(CACurrentMediaTime() - t0) sec" }

yields

1 sec
1 sec

This pull request modifies delay() so that the above example yields

1 sec
2 sec

I'm new to the library, so feel free to suggest changes or reject. Thanks!

Thomvis commented 8 years ago

Thanks for the PR!

The behavior of delay you found is indeed wrong, and the fix looks right to me. I have one remark that I'll post as an inline comment. I hope you can address that.

Thomvis commented 8 years ago

Thanks again! Merged.