Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queueMicrotask method to JSI #1331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rubennorte
Copy link
Contributor

Summary:
Changelog: [internal]

Context

Microtasks are an important aspect of JavaScript and they will become increasingly important in the hosts where we're currently using JSI.

For example, React Native is going to adopt an event loop processing model similar to the one on the Web, which means it would need the ability to schedule and execute microtasks in every iteration of the loop.

JSI already has a method to execute all pending microtasks (drainMicrotasks) but without a method to schedule microtasks this is incomplete.

We're currently testing microtasks with Hermes using an internal method to schedule microtasks (HermesInternal.enqueueJob) but we need a method in JSI so this also works in other runtimes like JSC and V8.

Changes

This adds the queueMicrotask to the Runtime API in JSI so we have symmetric API for microtasks and we can implement the necessary functionality.

The expectation for JSI implementations is to queue microtasks from this method and from built-ins like Promises and async functions in the same queue, and not drain that queue until explicitly done via drainMicrotasks in JSI.

This also modifies Hermes and JSC to provide stubs for those methods, and the actual implementation will be done in following diffs.

Differential Revision: D54302536

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 28, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D54302536

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D54302536

Summary:
Changelog: [internal]

## Context

Microtasks are an important aspect of JavaScript and they will become increasingly important in the hosts where we're currently using JSI.

For example, React Native is going to adopt an event loop processing model similar to the one on the Web, which means it would need the ability to schedule and execute microtasks in every iteration of the loop. See react-native-community/discussions-and-proposals#744 for details.

JSI already has a method to execute all pending microtasks (`drainMicrotasks`) but without a method to schedule microtasks this is incomplete.

We're currently testing microtasks with Hermes using an internal method to schedule microtasks (`HermesInternal.enqueueJob`) but we need a method in JSI so this also works in other runtimes like JSC and V8.

## Changes

This adds the `queueMicrotask` to the Runtime API in JSI so we have symmetric API for microtasks and we can implement the necessary functionality.

The expectation for JSI implementations is to queue microtasks from this method and from built-ins like Promises and async functions in the same queue, and not drain that queue until explicitly done via `drainMicrotasks` in JSI.

This also modifies Hermes and JSC to provide stubs for those methods, and the actual implementation will be done in following diffs.

Reviewed By: neildhar

Differential Revision: D54302536
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D54302536

tungdo194 pushed a commit to tungdo194/rn-test that referenced this pull request Apr 28, 2024
Summary:
X-link: facebook/hermes#1331

Changelog: [internal]

## Context

Microtasks are an important aspect of JavaScript and they will become increasingly important in the hosts where we're currently using JSI.

For example, React Native is going to adopt an event loop processing model similar to the one on the Web, which means it would need the ability to schedule and execute microtasks in every iteration of the loop. See react-native-community/discussions-and-proposals#744 for details.

JSI already has a method to execute all pending microtasks (`drainMicrotasks`) but without a method to schedule microtasks this is incomplete.

We're currently testing microtasks with Hermes using an internal method to schedule microtasks (`HermesInternal.enqueueJob`) but we need a method in JSI so this also works in other runtimes like JSC and V8.

## Changes

This adds the `queueMicrotask` to the Runtime API in JSI so we have symmetric API for microtasks and we can implement the necessary functionality.

The expectation for JSI implementations is to queue microtasks from this method and from built-ins like Promises and async functions in the same queue, and not drain that queue until explicitly done via `drainMicrotasks` in JSI.

This also modifies Hermes and JSC to provide stubs for those methods, and the actual implementation will be done in following diffs.

Reviewed By: neildhar

Differential Revision: D54302536
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants