question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise is not working inside callback

See original GitHub issue

Description

If worklet calls callback function - only body of this function is called. Functions scheduled for the next tick (promise) are not called (until some manul event)

const callWithPromise = () => {
  return Promise.resolve();
};

const Row = () => {
  return <View style={styles.row} />;
};

const Application = () => {
  const onSwipeCallback = useCallback(() => {
    console.log('[onSwipeCallback] was called');
    callWithPromise()
      .then(() => {
        console.log('[onSwipeCallback] promise then');
      })
      .catch(() => {
        console.log('[onSwipeCallback] promise catch');
      });
  }, []);

  return (
    <View style={styles.container}>
      <SwipableRow onSwipeLeft={onSwipeCallback} onSwipeRight={onSwipeCallback}>
        <Row />
      </SwipableRow>
    </View>
  );
};

This callback code is not working as expected. then callback should be called immediately, but it’s not.

Screenshots

Steps To Reproduce

Expected behavior

Promise should be scheduled and executed immidiately.

Actual behavior

Promise is not executed until some external event (touch screen)

Snack or minimal code example

SwipableRow.txt Application.txt

Package versions

  • React: 16.11.0
  • React Native: 0.62.2
  • React Native Reanimated: 2.0.0-alpha.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
karol-bisztygacommented, Aug 19, 2020

So I was able to reproduce the problem on Android using code provided by @likern. On iOS it works alright.

1reaction
Szymon20000commented, Aug 26, 2020

It’s only a temporary solution I’m working on a proper one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolving a promise after another callback is executed
In the current code resolve(outerResult) always runs before the callback so the promise always resolves to undefined. What you're asking here ...
Read more >
Resolving An Outer Promise Inside A Callback Function In ...
Here `Promise.resolve(m)` resolves the callback function and not the outer one. Callback.PNG. As it can be seen from this screenshot too ...
Read more >
How to rewrite a callback function in Promise form and async ...
If we don't pass in a callback, we get a TypeError: callback is not a function error. Promise version. And here's the Promise-based...
Read more >
Callback not working properly if I dont have debugger in my ...
Sounds like your callback function not really works. Callbacks/promises/async-await is used for asynchronous stuff when Innovator shall wait for another client ...
Read more >
Using promises - JavaScript - MDN Web Docs
This second promise ( promise2 ) represents the completion not just of doSomething() , but also of the successCallback or failureCallback you ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found