stefanwille / crystal-redis

Full featured Redis client for Crystal
MIT License
380 stars 61 forks source link

Execution gets stuck at the subscribe block #49

Closed plainas closed 6 years ago

plainas commented 6 years ago

I think this can be marked as a bug, because if it is a design choice, it's extremely limiting as we can only set up one subscriber and not to anything else.

The fact is that execution gets trapped in the subscribe block. The subscription works but the code stops there.

stefanwille commented 6 years ago

Are you using multiple threads?

plainas commented 6 years ago

Not that I am a ware of. I was trying to use this in a kemal app. Which didn't work because both kemal and crystal-redis pub sub required an event loop.

I commented out all code and left just the code from the pubsub example. I wen and red the docs that came with this module and it does appear that there is no way to subscribe without getting stuck in an event loop. Is that so?

plainas commented 6 years ago

I ended up wrapping the subscribe block inside a spawn block. Don't know if this approach is recomended. It is worth putting in the examples though.

stefanwille commented 6 years ago

I think now I get what you mean. You are calling subscribe and thread execution blocks, and you expected that it would continue instead.

This is how Redis subscriptions are designed. A different behaviour would require a new thread / a spawn in the API. The solution is to make a new Redis connection and a new thread.