NFT-Worlds / WRLD-Payments-API

https://www.nftworlds.com/
GNU Affero General Public License v3.0
12 stars 14 forks source link

Remove web3 calls from main thread #14

Closed 0xFlicker closed 2 years ago

0xFlicker commented 2 years ago

My understanding of the Minecraft event loop is that all events, unless explicitly async are called on the main thread. Web3 calls can block for long periods of time. I would assume that calls like these https://github.com/NFT-Worlds/WRLD-Payments-API/blob/main/src/main/java/com/nftworlds/wallet/objects/NFTPlayer.java#L31-L32 need to run async in order to allow the event handler to complete quickly. After they complete, emit a custom event to update state and subscribe to that to again update on the main thread, or use runTaskLater which is the mini inside-the-closure form of the same thing.

In my plugins, I always try to exit from an event handler as quickly as possible and use threads and custom events to synchronize actions.

jacobp925 commented 2 years ago

It's already off the main thread. (AsyncPlayerPreLoginEvent)

0xFlicker commented 2 years ago

thanks!