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.
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.
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
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:
- Introduce
ChannelShouldQuiesceUserEvent
- Handle
ChannelShouldQuiesceUserEvent
in theAcceptHandler
with closing the server socket - Handle ChannelShouldQuiesceUserEvent in the HTTPServerPipelineHandler by only handling a already in-flight request and then no longer accepting input
Result:
Handlers can now support quiescing
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:
- More correctness
- Less unexpected behaviour
- Also seems performance is impacted positively
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.
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
Want to know more or get inspired?
- Check out what we are working on now. You might see something you can collaborate with Issues
- Check out more Vapor awesomeness Awesome Vapor
- Some more Vapor learning material Vapor School
- Great resources from our community Vapor Forum
- Vapor’s Core team had published an early access book on Vapor through RW here
- Paul Hudson had also updated his Server Side Swift with Vapor book here
- Also the RW’s Vapor Video Course Server Side Swift with Vapor - Video Course
- Vapor Forum Vapor Forum
- Vapor Forum @swift.org Vapor@swift.org
Take action
There are many ways you can contribute with Vapor
- Star the project in GitHub
- Follow us on Twitter
- Follow us on Medium
- Become a backer
- Become a sponsor
- Come and talk to us