Promise is not working inside callback
See original GitHub issueDescription
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:
- Created 3 years ago
- Reactions:1
- Comments:23 (23 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I was able to reproduce the problem on Android using code provided by @likern. On iOS it works alright.
It’s only a temporary solution I’m working on a proper one.