vapor / async-kit

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

adding `performWithTask` convenience func to convert async works to futures #86

Closed MahdiBM closed 2 years ago

MahdiBM commented 2 years ago

This PR adds a convenience function to convert async works to futures, and reduces the need to directly use promises.

As an example, if you have the code below:

let promise = eventLoop.makePromise(of: SomeType.self)
promise.completeWithTask {
    try await myAsyncFunc()
}
return promise.futureResult

It can be reduced to:

return eventLoop.performWithTask {
    try await myAsyncFunc()
}
codecov-commenter commented 2 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (main@d774c10). Click here to learn what that means. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #86   +/-   ##
=======================================
  Coverage        ?   77.46%           
=======================================
  Files           ?       28           
  Lines           ?     1824           
  Branches        ?        0           
=======================================
  Hits            ?     1413           
  Misses          ?      411           
  Partials        ?        0           
Flag Coverage Δ
unittests 77.46% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d774c10...40ac9dc. Read the comment docs.

MahdiBM commented 2 years ago

Added a test to make sure it has the basic expected functionality. Feel free to suggest other kinds of needed tests if there are any.

gwynne commented 2 years ago

Overriding test failures to merge due to known issues with TSan and async/await at this time.