boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10.01k stars 706 forks source link

Async request #426

Closed janosimas closed 5 years ago

janosimas commented 5 years ago

Hi, I'm trying to do a few http requests on the onTurnBegin, I was able to do this but one request at a time. I was thinking about using promises to send all the requests at the same time but as far as I understand I cannot simply block until the promises resolves.

I there anyway of doing this? Has anyone tryed something similar?

nicolodavis commented 5 years ago

In general you should not be accessing external state inside your game logic.

What are you trying to achieve? Maybe you're looking for a callback on the client that's triggered on the beginning of a turn rather than using onTurnBegin, which is also called on the server?

janosimas commented 5 years ago

It's a game for learning new languages, I have a list of the most common nouns and I use an external service to translate the words and show as options.

When the turn begins, I get 5 random words and translate using a rest service. These translations will be shown as options to the player to guess the right translation.

The prototype is working and can be found at boardgame-server in the branch language-game.

Currently I'm using the sync-request package.

nicolodavis commented 5 years ago

I'm afraid this use-case doesn't map very well to the way this framework is designed (which expects all the game state to be available, rather than being queried during play). Feel free to continue to discussion on Gitter.