Created
February 26, 2022 14:14
-
-
Save mironal/bd511a211f6a300b32350b83350894eb to your computer and use it in GitHub Desktop.
Sample code for Stream API using TwitterAPIKit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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