Skip to content

Conversation

skusnierz
Copy link
Contributor

@skusnierz skusnierz commented Sep 16, 2025

Summary

Test plan

Empty example
import React from 'react';
import { Button, StyleSheet, View } from 'react-native';
import { createWorkletRuntime, runOnRuntimeAsync } from 'react-native-worklets';

export default function EmptyExample() {
  const runtime = createWorkletRuntime({ name: 'Test Worklet Runtime' });

  const runOnRuntimeAsyncThen = () => {
    // eslint-disable-next-line @typescript-eslint/no-floating-promises
    runOnRuntimeAsync(runtime, () => {
      'worklet';
      return '[Then] Hello from Test Worklet Runtime';
    }).then((result: string) => {
      console.log('Result:', result);
    });
  };

  const runOnRuntimeAsyncAwait = async () => {
    const result = await runOnRuntimeAsync(runtime, () => {
      'worklet';
      return '[Await] Hello from Test Worklet Runtime';
    });
    console.log('Result:', result);
  };

  const runOnRuntimeAsyncErrorWithCatch = () => {
    runOnRuntimeAsync(runtime, () => {
      'worklet';
      throw new Error('[Then] Error from Test Worklet Runtime');
    })
      .then((result: string) => {
        console.log('Result:', result);
      })
      .catch((error) => {
        console.log('Error:', error);
      });
  };

  const runOnRuntimeAsyncAwaitErrorWithCatch = async () => {
    try {
      const result = await runOnRuntimeAsync(runtime, () => {
        'worklet';
        throw new Error('[Await] Error from Test Worklet Runtime');
      });
      console.log('Result:', result);
    } catch (error) {
      console.log('Error:', error);
    }
  };

  const runOnRuntimeAsyncAwaitErrorWithoutCatch = async () => {
    const result = await runOnRuntimeAsync(runtime, () => {
      'worklet';
      throw new Error('[Await] Error from Test Worklet Runtime');
    });
    console.log('Result:', result);
  };

  const runOnRuntimeAsyncErrorWithoutCatch = () => {
    // eslint-disable-next-line @typescript-eslint/no-floating-promises
    runOnRuntimeAsync(runtime, () => {
      'worklet';
      throw new Error('[Await] Error from Test Worklet Runtime');
    }).then((result: string) => {
      console.log('Result:', result);
    });
  };

  return (
    <View style={styles.container}>
      <Button
        title="runOnRuntimeAsync Then"
        onPress={() => runOnRuntimeAsyncThen()}
      />
      <Button
        title="runOnRuntimeAsync Await"
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        onPress={() => runOnRuntimeAsyncAwait()}
      />
      <Button
        title="runOnRuntimeAsync Error Without Catch"
        onPress={() => runOnRuntimeAsyncErrorWithoutCatch()}
      />
      <Button
        title="runOnRuntimeAsync Await Error Without Catch"
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        onPress={() => runOnRuntimeAsyncAwaitErrorWithoutCatch()}
      />
      <Button
        title="runOnRuntimeAsync Error With Catch"
        onPress={() => runOnRuntimeAsyncErrorWithCatch()}
      />
      <Button
        title="runOnRuntimeAsync Await Error With Catch"
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        onPress={() => runOnRuntimeAsyncAwaitErrorWithCatch()}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

@skusnierz skusnierz marked this pull request as draft September 16, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant