Skip to content

Commit afd3a75

Browse files
Merge pull request #44 from pusher/asynchronous-note
Added asynchronous semaphore note for trigger method.
2 parents f2d1130 + bf63973 commit afd3a75

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,28 @@ self.pusher.trigger(event: publicEvent) { result in
197197
}
198198
```
199199

200+
**NOTES:**
201+
- The `trigger(…)` method is asynchronous. If you are not using this in a GUI application, you may need to use a semaphore:
202+
203+
```swift
204+
let publicChannel = Channel(name: "my-channel", type: .public)
205+
let publicEvent = try! Event(name: "my-event",
206+
data: "hello world!",
207+
channel: publicChannel)
208+
209+
let sema = DispatchSemaphore(value: 0)
210+
pusher.trigger(event: publicEvent) { result in
211+
switch result {
212+
case .success(let channelSummaries):
213+
// Inspect `channelSummaries
214+
case .failure(let error):
215+
// Handle error
216+
}
217+
sema.signal()
218+
}
219+
sema.wait()
220+
```
221+
200222
### Authenticating channel subscriptions
201223

202224
Users that attempt to subscribe to a private or presence channel must be first authenticated. An authentication token that can be returned to a user client that is attempting a subscription, which requires authentication with the server.

0 commit comments

Comments
 (0)