Commit 275ffab
committed
Add coroutines-based API with StateFlow extensions
Added coroutines-based API via extension functions to provide a modern
approach to working with Socket.IO without modifying the existing
callback-based API.
Main changes:
- Added suspend extension functions:
* Manager.openSuspend() - open connection using coroutines
* Socket.openSuspend() - open socket using coroutines
* Socket.emitSuspend() - emit events using coroutines
* Socket.emitSuspend(event, *args) { ack } - emit with ack (trailing lambda)
* IO.socketSuspend() - create socket using coroutines
- Added StateFlow and Flow extensions:
* Manager.stateFlow - track manager state
* Socket.connectedFlow - track connection state
* Socket.socketIdFlow - track socket ID
* Emitter.flow(event) - receive events via Flow
* Emitter.flowWithReplay(event, replay) - Flow with replay buffer
- Added usage examples (CoroutinesExample.kt):
* Basic API usage
* Error handling and subscription cancellation
* Reconnection with new parameters
* Proper resource cleanup
* Automatic reconnection handling
* Detailed explanation of Flow errors
* Importance of subscription order
- Added tests (CoroutinesExtensionsTest.kt):
* Coverage of all main usage scenarios
* Tests for all extension functions
* Tests for StateFlow and Flow extensions
* Tests for error handling
- Updated documentation (README.md):
* Added "Coroutines-based API (Recommended)" section
* Usage examples for all new functions
* Description of all available extension functions
All changes are backward compatible - existing callback-based API
remains unchanged. New API uses idiomatic Kotlin syntax with trailing
lambda for acknowledgements.1 parent 23153d5 commit 275ffab
6 files changed
Lines changed: 1744 additions & 0 deletions
File tree
- kmp-socketio/src
- commonMain/kotlin/com/piasy/kmp/socketio/socketio
- commonTest/kotlin/com/piasy/kmp/socketio/socketio
- jvmTest/kotlin/com/piasy/kmp/socketio/socketio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
56 | 99 | | |
57 | 100 | | |
58 | 101 | | |
59 | 102 | | |
60 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
61 | 117 | | |
62 | 118 | | |
63 | 119 | | |
| |||
0 commit comments