swift-nio icon indicating copy to clipboard operation
swift-nio copied to clipboard

Add a new overloading function completeWith to EventLoopPromise class.

Open Hailong opened this issue 4 years ago • 14 comments

Add a new overloading function completeWith to EventLoopPromise class.

Motivation:

  • Replace global helper function executeAndComplete() with class method for better encapsulation.
  • Get rid of the repeated pattern of checking whether the event loop is "current".

Modifications:

  • Removed global function executeAndComplete().
  • Added a new overloading of the completeWith() method to EventLoopPromise class.

Result:

Simplified the consumers of this functionality in code. And the new added overloading supports crossing event loop as well.

Hailong avatar Feb 09 '21 07:02 Hailong

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Can one of the admins verify this patch?

swift-server-bot avatar Feb 09 '21 07:02 swift-server-bot

Thanks for this patch! Out of curiosity, is it necessary to hop the loop? EventLoopPromise is entirely thread-safe and can absolutely be executed on any thread. Unless you have a specific reason to want to do the loop hopping, I think we can safely remove that from this.

Lukasa avatar Feb 09 '21 07:02 Lukasa

Thanks for this patch! Out of curiosity, is it necessary to hop the loop? EventLoopPromise is entirely thread-safe and can absolutely be executed on any thread. Unless you have a specific reason to want to do the loop hopping, I think we can safely remove that from this.

@Lukasa there is no specific reason for me to do the loop hopping, I was just trying to keep the original logics as much as possible. I'm little confused about what you are referring to remove, can you please give me some hints and I can look at it more closely.

Hailong avatar Feb 09 '21 08:02 Hailong

The original logic of the exact function you're replacing didn't do if eventLoop.inEventLoop and then conditionally call execute. This is not really necessary, and can be removed.

Lukasa avatar Feb 09 '21 09:02 Lukasa