creationix / seaduk

An implementation of nucleus-js using duktape and libuv implemented in C
Other
34 stars 5 forks source link

Fix uv.write to allow concurrent writes. #4

Closed creationix closed 8 years ago

creationix commented 8 years ago

Libuv has an internal write queue and uv.shutdown API that allows for concurrent calls to uv.write to be performed. It will do the actual writes one at a time. Shutdown is a way to wait for all pending writes to finish.

But with the current bindings, we have singleton callback and request objects per method per handle meaning a single uv_stream_t instance can only have one uv.write() call at a time.

Recently a bug was fixed so that even serial calls can work, but more work is needed to make it fully take advantage of libuv's internal queue. (https://github.com/nucleus-js/seaduk/commit/ec3fa65a23743df729eb1206576c53c144b06442)

creationix commented 8 years ago

We'll somehow need to store the callback with the request object instead of with the handle as is currently done. But we still need a way to keep the request rooted in the GC while it's in-flight. Perhaps we can stick it to some global array? We do know that all libuv requests will call a C callback when they are ready to be cleaned up.