Skip to content

Conversation

@zztkm
Copy link
Contributor

@zztkm zztkm commented Nov 13, 2025

No description provided.

@zztkm

This comment was marked as duplicate.

@github-actions

This comment was marked as resolved.

@zztkm

This comment was marked as resolved.

@zztkm

This comment was marked as duplicate.

@github-actions

This comment was marked as resolved.

@zztkm

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@zztkm

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@zztkm zztkm requested a review from t-miya November 14, 2025 04:30
@zztkm zztkm changed the title [WIP] getStats メソッドを追加する getStats メソッドを追加する Nov 14, 2025
suspendCancellableCoroutine { continuation ->
// 現在の PeerChannel インスタンスを取得
val currentPeer = peer
// PeerChannel がまだ存在しない場合のガード
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

切断済みの場合でも null のはずなので まだ はいらなそうです

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにそうですね、修正します

val currentPeer = peer
// PeerChannel がまだ存在しない場合のガード
if (currentPeer == null) {
// 結果なしを即時返却
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数ドキュメントにも書いていますが、結果なし を返しているのではなく、null を明示的に返すようにしているので null を返す、にした方がよさそうです


currentPeer.getStats { report ->
// コルーチンがまだアクティブな場合に結果を返却
// そうでない場合は何もしない
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何もしないで大丈夫なんでしたっけ
continuation.resume(null) で終わる必要ないですか?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

アクティブでないなら大丈夫なのか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大丈夫です。
すでにキャンセルされてしまってるので resume すると例外が発生するので、例外発生させるのではなくここはキャンセルされた場合スルーするようにしています。

本来はキャンセルされたときの処理を書けという感じなのですが、ラップしてる非同期コールバックの getStats 呼び出しをキャンセルする方法がなさそうなので、このようにしています。

@zztkm zztkm merged commit 3492e85 into develop Nov 14, 2025
4 checks passed
@zztkm zztkm deleted the feature/get-stats branch November 14, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants