-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
336 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
android/runtime/common/src/java/org/appcelerator/kroll/KrollPromise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.appcelerator.kroll; | ||
|
||
import org.appcelerator.kroll.common.TiMessenger; | ||
|
||
public interface KrollPromise<V> { | ||
|
||
interface OnExecuteCallback<V> { | ||
void onExecute(KrollPromise<V> promise); | ||
} | ||
|
||
void resolve(V value); | ||
|
||
void reject(Object value); | ||
|
||
static <V> KrollPromise<V> create(OnExecuteCallback<V> callback) | ||
{ | ||
final KrollPromise<V> promise = KrollRuntime.getInstance().createPromise(); | ||
TiMessenger.postOnRuntime(() -> { | ||
callback.onExecute(promise); | ||
}); | ||
return promise; | ||
} | ||
|
||
static class NullPromise implements KrollPromise | ||
{ | ||
@Override | ||
public void resolve(Object value) {} | ||
@Override | ||
public void reject(Object value) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
android/runtime/v8/src/java/org/appcelerator/kroll/runtime/v8/V8Promise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.appcelerator.kroll.runtime.v8; | ||
|
||
import android.os.Message; | ||
|
||
import org.appcelerator.kroll.KrollPromise; | ||
import org.appcelerator.kroll.KrollRuntime; | ||
import org.appcelerator.kroll.common.AsyncResult; | ||
import org.appcelerator.kroll.common.TiMessenger; | ||
|
||
/** | ||
* This class wraps an underlying v8::Promise::Resolver which holds | ||
* the Promise but allows us to call resolve/reject on it. | ||
*/ | ||
public class V8Promise<V extends Object> extends V8Object implements KrollPromise<V> | ||
{ | ||
private static final String TAG = "V8Promise"; | ||
|
||
protected static final int MSG_RESOLVE = V8Object.MSG_LAST_ID + 100; | ||
protected static final int MSG_REJECT = V8Object.MSG_LAST_ID + 101; | ||
protected static final int MSG_LAST_ID = MSG_REJECT; | ||
|
||
public V8Promise() | ||
{ | ||
super(nativeCreate()); | ||
} | ||
|
||
@Override | ||
public void resolve(V value) | ||
{ | ||
if (KrollRuntime.getInstance().isRuntimeThread()) { | ||
nativeResolve(getPointer(), value); | ||
} else { | ||
TiMessenger.sendBlockingRuntimeMessage(handler.obtainMessage(MSG_RESOLVE), value); | ||
} | ||
} | ||
|
||
@Override | ||
public void reject(Object value) | ||
{ | ||
if (KrollRuntime.getInstance().isRuntimeThread()) { | ||
nativeReject(getPointer(), value); | ||
} else { | ||
TiMessenger.sendBlockingRuntimeMessage(handler.obtainMessage(MSG_REJECT), value); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean handleMessage(Message message) | ||
{ | ||
switch (message.what) { | ||
case MSG_RESOLVE: { | ||
AsyncResult asyncResult = ((AsyncResult) message.obj); | ||
Object value = asyncResult.getArg(); | ||
nativeResolve(getPointer(), value); | ||
asyncResult.setResult(null); | ||
return true; | ||
} | ||
case MSG_REJECT: { | ||
AsyncResult asyncResult = ((AsyncResult) message.obj); | ||
Object value = asyncResult.getArg(); | ||
nativeReject(getPointer(), value); | ||
asyncResult.setResult(null); | ||
return true; | ||
} | ||
} | ||
|
||
return super.handleMessage(message); | ||
} | ||
|
||
// JNI method prototypes | ||
private static native long nativeCreate(); | ||
|
||
private native void nativeResolve(long resolver, Object value); | ||
|
||
private native void nativeReject(long resolver, Object value); | ||
|
||
protected native boolean nativeRelease(long resolver); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.