Skip to content

Consider adding EventLoopGroupProvider.eventLoopGroup and EventLoopGroupProvider.syncShutDownIfNotShared #1655

@MrLotU

Description

@MrLotU

In NIO 2.21.0 a new enum EventLoopGroupProvider was introduced for easy passing around of EventLoopGroups in third party libraries.

This has been a great tool in lots of places, but still leaves the following code in nearly all client-libraries:

let eventLoopGroup: EventLoopGroup

switch eventLoopGroupProvider {
case .shared(let elg): eventLoopGroup = elg
case .createNew: eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
}

or something very similar. And along with this "setup" code almost all these blocks also come with a similar switch statement to shut down the ELG when .createNew or pass over when .shared()


I would like to propose one new method and one new property to be added to EventLoopGroupProvider.
First off EventLoopGroupProvider.eventLoopGroup that would return the EventLoopGroup in a one-liner, using the above switch statement internally.

Second off EventLoopGroupProvider.syncShutDownIfNotShared to shut down the ELG in case it's been newly created.


Curious to hear your input on if this has a place within NIO, or should stay in third-party libraries. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions