mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.java (#45672)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45672 Changelog: [Internal] Reviewed By: cortinico Differential Revision: D60233395 fbshipit-source-id: fdef561f48eab2ec8291fd3ea697e107249e3464
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3e3f9fc060
commit
8c01290b1f
@@ -1986,8 +1986,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 {
|
||||
|
||||
-36
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.Dispatcher
|
||||
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) {
|
||||
// client.dispatcher is private, so we need to use reflection to access
|
||||
// it via method dispatcher() otherwise we will get a compile error:
|
||||
// Using 'dispatcher(): Dispatcher' is an error. moved to val
|
||||
val dispatcherMethod = OkHttpClient::class.java.getMethod("dispatcher")
|
||||
dispatcherMethod.setAccessible(true)
|
||||
val dispatcher = dispatcherMethod.invoke(client) as Dispatcher
|
||||
for (call in dispatcher.queuedCalls()) {
|
||||
if (tag == call.request().tag()) {
|
||||
call.cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
for (call in dispatcher.runningCalls()) {
|
||||
if (tag == call.request().tag()) {
|
||||
call.cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user