Skip to content

Commit 478534a

Browse files
committed
レースコンディションになりそうな箇所を修正する
1 parent 5281e96 commit 478534a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sora/MediaChannel.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ public final class MediaChannel {
154154
/// サーバーから通知を受信可能であり、接続中にのみ取得可能です。
155155
public private(set) var subscriberCount: Int?
156156

157-
/// RPC を扱うチャネル
158-
/// - Note: RPC が利用不可の場合は nil を返します
159-
public var rpcChannel: RPCChannel? {
160-
peerChannel.rpcChannel
161-
}
162-
163157
/// RPC で利用可能なメソッド一覧
164158
///
165159
/// Sora サーバーから通知された RPC メソッドが列挙型として取得できます。
@@ -307,7 +301,9 @@ public final class MediaChannel {
307301
) async throws -> RPCResponse<M.Result>? {
308302
let response = try await withCheckedThrowingContinuation {
309303
(continuation: CheckedContinuation<RPCResponse<Any>?, Error>) in
310-
guard let rpcChannel else {
304+
// ローカル変数で参照を保持することで rpc メソッド呼び出し時点での
305+
// rpcChannel インスタンス生存を保障する。
306+
guard let rpcChannel = self.peerChannel.rpcChannel else {
311307
continuation.resume(
312308
throwing: SoraError.rpcUnavailable(reason: "rpc channel is not available"))
313309
return

0 commit comments

Comments
 (0)