Kotlinify OkHttpCallUtil (#43825)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43825

Changelog: [Internal]

As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)).

Reviewed By: cortinico

Differential Revision: D55707704

fbshipit-source-id: 658f2aed252abfd75f8d7670ca35a396ed06390a
This commit is contained in:
Fabrizio Cucci
2024-04-04 04:02:55 -07:00
committed by Facebook GitHub Bot
parent c1081cc1ac
commit 0646d50306
3 changed files with 35 additions and 38 deletions
@@ -1936,8 +1936,9 @@ public final class com/facebook/react/common/mapbuffer/WritableMapBuffer : com/f
public final fun put (IZ)Lcom/facebook/react/common/mapbuffer/WritableMapBuffer;
}
public class com/facebook/react/common/network/OkHttpCallUtil {
public static fun cancelTag (Lokhttp3/OkHttpClient;Ljava/lang/Object;)V
public final class com/facebook/react/common/network/OkHttpCallUtil {
public static final field INSTANCE Lcom/facebook/react/common/network/OkHttpCallUtil;
public static final fun cancelTag (Lokhttp3/OkHttpClient;Ljava/lang/Object;)V
}
public class com/facebook/react/config/ReactFeatureFlags {
@@ -1,36 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.common.network;
import com.facebook.infer.annotation.Nullsafe;
import okhttp3.Call;
import okhttp3.OkHttpClient;
/**
* Helper class that provides the necessary methods for canceling queued and running OkHttp calls
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
public class OkHttpCallUtil {
private OkHttpCallUtil() {}
public static void cancelTag(OkHttpClient client, Object tag) {
for (Call call : client.dispatcher().queuedCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
return;
}
}
for (Call call : client.dispatcher().runningCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
return;
}
}
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.common.network
import okhttp3.OkHttpClient
/**
* Helper class that provides the necessary methods for canceling queued and running OkHttp calls
*/
public object OkHttpCallUtil {
@JvmStatic
public fun cancelTag(client: OkHttpClient, tag: Any) {
for (call in client.dispatcher().queuedCalls()) {
if (tag == call.request().tag()) {
call.cancel()
return
}
}
for (call in client.dispatcher().runningCalls()) {
if (tag == call.request().tag()) {
call.cancel()
return
}
}
}
}