Skip to content

Commit

Permalink
Migrate Promise interface to Kotlin (facebook#44587)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44587

# Changelog:
[Internal] -

As in the title, moving towards migrating all the interfaces in react.bridge.

Differential Revision: D57433401
  • Loading branch information
rshest authored and facebook-github-bot committed May 16, 2024
1 parent a2958fe commit 65b9e32
Showing 1 changed file with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
package com.facebook.react.bridge

/*
* Interface that represents a JavaScript Promise which can be passed to the native module as a
Expand All @@ -18,29 +15,28 @@
* will be marked as "promise" and will return a promise when invoked from JavaScript.
*/
public interface Promise {

/**
* Successfully resolve the Promise with an optional value.
*
* @param value Object
*/
void resolve(@Nullable Object value);
public fun resolve(value: Any?)

/**
* Report an error without an exception using a custom code and error message.
*
* @param code String
* @param message String
*/
void reject(String code, String message);
public fun reject(code: String, message: String)

/**
* Report an exception with a custom code.
*
* @param code String
* @param throwable Throwable
*/
void reject(String code, Throwable throwable);
public fun reject(code: String, throwable: Throwable?)

/**
* Report an exception with a custom code and error message.
Expand All @@ -49,36 +45,35 @@ public interface Promise {
* @param message String
* @param throwable Throwable
*/
void reject(String code, String message, Throwable throwable);
public fun reject(code: String, message: String, throwable: Throwable?)

/**
* Report an exception, with default error code. Useful in catch-all scenarios where it's unclear
* why the error occurred.
*
* @param throwable Throwable
*/
void reject(Throwable throwable);
public fun reject(throwable: Throwable?)

/* ---------------------------
* With userInfo WritableMap
* --------------------------- */

/**
* Report an exception, with default error code, with userInfo. Useful in catch-all scenarios
* where it's unclear why the error occurred.
*
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(Throwable throwable, WritableMap userInfo);
public fun reject(throwable: Throwable?, userInfo: WritableMap)

/**
* Reject with a code and userInfo WritableMap.
*
* @param code String
* @param userInfo WritableMap
*/
void reject(String code, @NonNull WritableMap userInfo);
public fun reject(code: String, userInfo: WritableMap)

/**
* Report an exception with a custom code and userInfo.
Expand All @@ -87,7 +82,7 @@ public interface Promise {
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(String code, Throwable throwable, WritableMap userInfo);
public fun reject(code: String, throwable: Throwable, userInfo: WritableMap)

/**
* Report an error with a custom code, error message and userInfo, an error not caused by an
Expand All @@ -97,7 +92,7 @@ public interface Promise {
* @param message String
* @param userInfo WritableMap
*/
void reject(String code, String message, @NonNull WritableMap userInfo);
public fun reject(code: String, message: String, userInfo: WritableMap)

/**
* Report an exception with a custom code, error message and userInfo.
Expand All @@ -107,18 +102,11 @@ public interface Promise {
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(String code, String message, Throwable throwable, WritableMap userInfo);

/* ------------
* Deprecated
* ------------ */
public fun reject(code: String, message: String, throwable: Throwable?, userInfo: WritableMap)

/**
* Report an error which wasn't caused by an exception.
*
* @deprecated Prefer passing a module-specific error code to JS. Using this method will pass the
* error code "EUNSPECIFIED".
*/
@Deprecated
void reject(String message);
/** Report an error which wasn't caused by an exception. */
@Deprecated(
"""Prefer passing a module-specific error code to JS. Using this method will pass the
error code EUNSPECIFIED""")
public fun reject(message: String)
}

0 comments on commit 65b9e32

Please sign in to comment.