New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a means to wait until a file lock can be acquired #22081
Comments
Marked this as blocking #21476. |
This is an option in the APIs on all platforms. So the sync version can block until the lock becomes available and the async version complete when the locks becomes available. This could be exposed in the API either through new methods lockWait or by adding an additional argument to lock/lockSync. Adding an additional argument might tip the balance towards optional named arguments. Added this to the 1.9 milestone. |
This comment was originally written by @seaneagan You probably wouldn't want to wait indefinitely, what about a timeout argument: lock(FileLock mode, {Duration timeout = Duration.ZERO, ...}); By default the timeout is zero, matching the current behavior. There is no way to wait indefinitely, which might be a good thing? |
The problem with providing a timeout is that the OS APIs does not have a timeout option, and no explicit way of canceling the call. On Linux and Mac OS sending a signal will make the call return EINTR, and that can be used to cancel the call. On Windows that is not possible. On Windows it might be possible to schedule LockFileEx as an asynchronous operation completing through a completion port, and then cancel the request using CancelIo if it does not complete before the timeout. However currently we only use completion ports for socket IO, so that might require a larger change. You can use the timeout method on a Future (https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:async.Future#id_timeout) to get a Future that completes after a timeout if the original Future does not complete. However the original Future might still complete at some later point. |
Set owner to @sgjesse. |
I assume this isn't a high priority issue (not marked as such) so I'm removing the explicit milestone label. Removed this from the 1.10 milestone. |
678cb04 adds a blocking option to |
The existing file locking functions only provide the means to check whether a lock is available at a given point in time. Applications frequently want to acquire a lock immediately upon it becoming available, and I believe the OS APIs provide the means to do so. Please expose this in the API.
The text was updated successfully, but these errors were encountered: