Skip to content

Instantly share code, notes, and snippets.

@mironal
Created February 26, 2022 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mironal/bd511a211f6a300b32350b83350894eb to your computer and use it in GitHub Desktop.
Save mironal/bd511a211f6a300b32350b83350894eb to your computer and use it in GitHub Desktop.
Sample code for Stream API using TwitterAPIKit.
func testExample() throws {
let client = TwitterAPIKit(
.bearer(
"token"
))
let exp = expectation(description: "")
let task = client.v2.sampleStream(.init())
Task {
for await response in task.streamResponse(queue: .global(qos: .default)) {
print(response.prettyString)
if response.isError {
exp.fulfill()
break
}
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(20)) {
task.cancel()
}
wait(for: [exp], timeout: 10000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment