datanoise / mongo.cr

Crystal binding for MongoDB C Driver
MIT License
97 stars 35 forks source link

Mongo.cr and the event loop #29

Open ursuscamp opened 7 years ago

ursuscamp commented 7 years ago

Does mongo.cr use the asynchronous event loop provided by Crystal, or will it block?

datanoise commented 7 years ago

mongo.cr is using mongoc driver which by default is using libc IO. So it will block the process. As an experiment I implemented src/mongo/stream.cr to delegate all IO operations to crystal event loop. Please try it and let me know if it helps.

ursuscamp commented 7 years ago

Looking through the code, it seems all it needs to set it up is to call setup_stream on the Mongo::Client instance. Is that correct?

datanoise commented 7 years ago

That's correct.