Week 17

News

New version of SwiftNIO was released this week. Vapor running everywhere, this week on a Raspberry Pi!.

New Features

Process async execute

Adds support for asynchronously execute a process. Asynchronously the supplied program in a new process. Stderr and stdout will be supplied to the output closure as it is received. The returned future will finish when the process has terminated.

let status = try Process.asyncExecute("echo", "hi", on: ...) { output in
    print(output) // ProcessOutput (stderr or stdout)
}.wait()
print(result) // 0

NIO

Current version 1.7.1

Rename numThreads to numberOfThreads parameter

Motivation:

We should be consistent with naming and also choose descriptive names.

Modifications:

Deprecate old init method that uses numThreads Add new init with numberOfThreads param name Everywhere use the new init

Result:

More consistent and descriptive naming. Fixes #432.

apple/swift-nio#443

Make removeHandlers public

Motivation:

If ChannelPipeline.removeHandlers is internal it is extremely difficult to implement a correct ChannelCore.

Modifications:

Make ChannelPipeline.removeHandlers public.

Result:

Easier to implement ChannelCore.

apple/swift-nio#408

Do not allocate String to check if HTTP message is keep alive

Motivation:

We can check if a HTTP message is using keep alive without any allocation.

Modifications:

Directly act on the internal storage of HTTPHeaders to find out if keep alive is used or not.

Result:

Less allocations

apple/swift-nio#402

Channel quiescing support

Motivation:

In certain cases it’s useful to quiesce a channel instead of just closing them immediately for example when receiving a signal.

This lays the groundwork by introducing the ChannelShouldQuiesceUserEvent user event that when received can be interpreted by a ChannelHandler in a protocol & application specific way. Some protocols support tear down and that would be a good place to initiate the tear down.

Modifications:

Result:

Handlers can now support quiescing

apple/swift-nio#399

Fix EventLoops that Bootstrap channel initialiser’s call out on

Motivation:

Previously we were not running the (child/server)channelInitializers on the event loop associated to the Channel we’re initialising. Almost all operations in there are pipeline modifications which are thread safe so it presumably wasn’t a massive correctness issue. However it’s very expensive to hop threads that often and it is also very unexpected. This addresses this issue.

Modifications:

Made all (child/server)channelInitializers run on the event loop that is associated to their Channel

Result:

apple/swift-nio#424

Community Contributions

Fix numeric with leading zero fractional

Numeric numbers with a fractional part with a leading zero (eg: 10.08) will be decoded from the database without the leading zero (ie: 10.80).

This is a serious issue which results in corrupted numeric values.

vapor/postgresql#68

Tagged releases

Articles

Working with Futures in Vapor 3

Brought to you by @anapaix

Working with Futures in Vapor 3

Basic Authentication with Vapor 3

Brought to you by @kezzy

Basic Authentication with Vapor 3

Vapor 3 on Raspberry Pi

Brought to you by @cakinney

Vapor 3 on Raspberry Pi

Want to know more or get inspired?

Take action

There are many ways you can contribute with Vapor

Vapor communities around the world

Vapor Berlin

Vapor London

Vapor Boston

Writing Credits

@frivas

@twof