Skip to content

Commit

Permalink
Merge pull request #133 from d-exclaimation/bump-version-fix-task
Browse files Browse the repository at this point in the history
fix: Fixed using onText incorrectly in async task
  • Loading branch information
d-exclaimation authored Jun 14, 2023
2 parents 387c2a4 + 68326e3 commit ca7d455
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
- 'version-*'

jobs:
five-five:
five-six:
container:
image: swift:xenial
image: swift:5.6
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 4 additions & 4 deletions Documentation/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Add these dependencies and [Pioneer](/) to the `Package.swift`
```swift filename="Package.swift" showLineNumbers copy
let package = Package(
dependencies: [
.package(url: "https://github.com/GraphQLSwift/Graphiti.git", from: "1.2.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.67.1"),
.package(url: "https://github.com/d-exclaimation/pioneer", from: "1.0.0")
.package(url: "https://github.com/GraphQLSwift/Graphiti.git", from: "1.2.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.77.1"),
.package(url: "https://github.com/d-exclaimation/pioneer", from: "1.3.0")
],
targets: [
.target(
Expand All @@ -54,7 +54,7 @@ let package = Package(
)
```

### Using Swift 5.5.2 or higher
### Using Swift 6 or higher

We will also restrict the platform of the project to macOS v10.15 or higher, to allow the use of Swift Concurrency.

Expand Down
76 changes: 38 additions & 38 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,62 @@
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
"state": {
"branch": null,
"revision": "794dc9d42720af97cedd395e8cd2add9173ffd9a",
"version": "1.11.1"
"revision": "78db67e5bf4a8543075787f228e8920097319281",
"version": "1.18.0"
}
},
{
"package": "async-kit",
"repositoryURL": "https://github.com/vapor/async-kit.git",
"state": {
"branch": null,
"revision": "929808e51fea04f01de0e911ce826ef70c4db4ea",
"version": "1.15.0"
"revision": "a61da00d404ec91d12766f1b9aac7d90777b484d",
"version": "1.17.0"
}
},
{
"package": "console-kit",
"repositoryURL": "https://github.com/vapor/console-kit.git",
"state": {
"branch": null,
"revision": "c085098102c18ac5b3eac741fd4101868ddb5a2e",
"version": "4.4.1"
"revision": "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4",
"version": "4.6.0"
}
},
{
"package": "Graphiti",
"repositoryURL": "https://github.com/GraphQLSwift/Graphiti.git",
"state": {
"branch": null,
"revision": "8c0048e217b185da163c8ba83475948dc5b0174e",
"version": "1.2.2"
"revision": "f80bd1342e52b9ee9e19f7f017dc4545e6c3cb6d",
"version": "1.10.1"
}
},
{
"package": "GraphQL",
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
"state": {
"branch": null,
"revision": "a3011344bef0374fb72f4ad57a85460564eb8f0e",
"version": "2.4.5"
"revision": "1b9d48ce0f0ad8280f75ce9914579aaac5881bc6",
"version": "2.5.1"
}
},
{
"package": "multipart-kit",
"repositoryURL": "https://github.com/vapor/multipart-kit.git",
"state": {
"branch": null,
"revision": "0d55c35e788451ee27222783c7d363cb88092fab",
"version": "4.5.2"
"revision": "1adfd69df2da08f7931d4281b257475e32c96734",
"version": "4.5.4"
}
},
{
"package": "routing-kit",
"repositoryURL": "https://github.com/vapor/routing-kit.git",
"state": {
"branch": null,
"revision": "9e181d685a3dec1eef1fc6dacf606af364f86d68",
"version": "4.5.0"
"revision": "611bc45c5dfb1f54b84d99b89d1f72191fb6b71b",
"version": "4.7.2"
}
},
{
Expand All @@ -78,8 +78,8 @@
"repositoryURL": "https://github.com/apple/swift-atomics.git",
"state": {
"branch": null,
"revision": "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version": "1.0.2"
"revision": "6c89474e62719ddcc1e9614989fff2f68208fe10",
"version": "1.1.0"
}
},
{
Expand All @@ -96,80 +96,80 @@
"repositoryURL": "https://github.com/apple/swift-collections",
"state": {
"branch": null,
"revision": "48254824bb4248676bf7ce56014ff57b142b77eb",
"version": "1.0.2"
"revision": "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version": "1.0.4"
}
},
{
"package": "swift-crypto",
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "d9825fa541df64b1a7b182178d61b9a82730d01f",
"version": "2.1.0"
"revision": "33a20e650c33f6d72d822d558333f2085effa3dc",
"version": "2.5.0"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
"version": "1.4.2"
"revision": "32e8d724467f8fe623624570367e3d50c5638e46",
"version": "1.5.2"
}
},
{
"package": "swift-metrics",
"repositoryURL": "https://github.com/apple/swift-metrics.git",
"state": {
"branch": null,
"revision": "1c1408bf8fc21be93713e897d2badf500ea38419",
"version": "2.3.1"
"revision": "34025104068262db0cc998ace178975c5ff4f36b",
"version": "2.4.0"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "edfceecba13d68c1c993382806e72f7e96feaa86",
"version": "2.44.0"
"revision": "6213ba7a06febe8fef60563a4a7d26a4085783cf",
"version": "2.54.0"
}
},
{
"package": "swift-nio-extras",
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
"state": {
"branch": null,
"revision": "a75e92bde3683241c15df3dd905b7a6dcac4d551",
"version": "1.12.1"
"revision": "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
"version": "1.19.0"
}
},
{
"package": "swift-nio-http2",
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
"state": {
"branch": null,
"revision": "108ac15087ea9b79abb6f6742699cf31de0e8772",
"version": "1.22.0"
"revision": "a8ccf13fa62775277a5d56844878c828bbb3be1a",
"version": "1.27.0"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "42436a25ff32c390465567f5c089a9a8ce8d7baf",
"version": "2.20.0"
"revision": "e866a626e105042a6a72a870c88b4c531ba05f83",
"version": "2.24.0"
}
},
{
"package": "swift-nio-transport-services",
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
"state": {
"branch": null,
"revision": "2cb54f91ddafc90832c5fa247faf5798d0a7c204",
"version": "1.13.0"
"revision": "41f4098903878418537020075a4d8a6e20a0b182",
"version": "1.17.0"
}
},
{
Expand All @@ -186,17 +186,17 @@
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "888c8b68642c1d340b6b3e9b2b8445fb0f6148c9",
"version": "4.68.0"
"revision": "9a340de4995e5a9dade4ff4c51cd2e6ae30c12d6",
"version": "4.77.0"
}
},
{
"package": "websocket-kit",
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
"state": {
"branch": null,
"revision": "2d9d2188a08eef4a869d368daab21b3c08510991",
"version": "2.6.1"
"revision": "53fe0639a98903858d0196b699720decb42aee7b",
"version": "2.14.0"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.4.5"),
.package(url: "https://github.com/GraphQLSwift/Graphiti.git", from: "1.2.2"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.68.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.77.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
22 changes: 12 additions & 10 deletions Sources/Pioneer/Vapor/WebSocket/Pioneer+WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ public extension Pioneer {

/// Should upgrade callback
internal func shouldUpgrade(req: Request) -> EventLoopFuture<HTTPHeaders?> {
req.eventLoop.next().makeSucceededFuture(.init([("Sec-WebSocket-Protocol", websocketProtocol.name)]))
req.eventLoop.makeSucceededFuture(.init([("Sec-WebSocket-Protocol", websocketProtocol.name)]))
}

/// On upgrade callback
internal func onUpgrade(req: Request, ws: WebSocket, context: @escaping VaporWebSocketContext, guard: @escaping VaporWebSocketGuard) {
let cid = UUID()

// Tasks for handling keep alive internal and connectiontimeout
let keepAlive = keepAlive(using: ws)

let timeout = timeout(using: ws, keepAlive: keepAlive)

// Task for consuming WebSocket messages to avoid cyclic references and provide cleaner code
let receiving = Task {
let stream = AsyncStream(String.self) { con in
ws.onText { con.yield($1) }

con.onTermination = { @Sendable _ in
guard ws.isClosed else { return }
_ = ws.close()
}
// Synchronously consume WebSocket messages as a stream to avoid wrapping in a Task and cyclic references
let stream = AsyncStream(String.self) { con in
ws.onText { con.yield($1) }

con.onTermination = { @Sendable _ in
guard ws.isClosed else { return }
_ = ws.close()
}
}

// Task for consuming WebSocket messages collected from the stream
let receiving = Task {
for await message in stream {
await receiveMessage(
cid: cid, io: ws,
Expand Down

0 comments on commit ca7d455

Please sign in to comment.