change the #:get-lock-file argument of call-with-file-lock/timeout to #:lock-file
This commit is contained in:
parent
78a999537d
commit
997813680d
|
@ -175,7 +175,7 @@
|
|||
[else 'exists]))
|
||||
|
||||
(define (call-with-file-lock/timeout fn kind thunk failure-thunk
|
||||
#:get-lock-file [get-lock-file (λ () (make-lock-file-name fn))]
|
||||
#:lock-file [lock-file #f]
|
||||
#:delay [delay 0.01]
|
||||
#:max-delay [max-delay 0.2])
|
||||
|
||||
|
@ -187,18 +187,14 @@
|
|||
(raise-type-error 'call-with-file-lock/timeout "procedure (arity 0)" thunk))
|
||||
(unless (and (procedure? thunk) (= (procedure-arity thunk) 0))
|
||||
(raise-type-error 'call-with-file-lock/timeout "procedure (arity 0)" failure-thunk))
|
||||
(unless (or (path-string? get-lock-file)
|
||||
(and (procedure? get-lock-file) (= (procedure-arity get-lock-file) 0)))
|
||||
(raise-type-error 'call-with-file-lock/timeout "procedure (arity 0) returning a path-string? or path-string?" get-lock-file))
|
||||
(unless (path-string? lock-file)
|
||||
(raise-type-error 'call-with-file-lock/timeout "path-string? or #f" lock-file))
|
||||
(unless (and (real? delay) (not (negative? delay)))
|
||||
(raise-type-error 'call-with-file-lock/timeout "non-negative real" delay))
|
||||
(unless (and (real? max-delay) (not (negative? max-delay)))
|
||||
(raise-type-error 'call-with-file-lock/timeout "non-negative real" max-delay))
|
||||
|
||||
(define real-lock-file
|
||||
(if (procedure? get-lock-file) (get-lock-file) get-lock-file))
|
||||
(unless (path-string? real-lock-file)
|
||||
(raise-type-error 'call-with-file-lock/timeout "procedure (arity 0) returning a path-string? or path-string?" get-lock-file))
|
||||
(define real-lock-file (or lock-file (make-lock-file-name fn)))
|
||||
(let loop ([delay delay])
|
||||
(call-with-file-lock
|
||||
kind
|
||||
|
|
|
@ -1056,30 +1056,29 @@ with the given @racket[lock-there], instead.}
|
|||
[kind (or/c 'shared 'exclusive)]
|
||||
[thunk (-> any)]
|
||||
[failure-thunk (-> any)]
|
||||
[#:get-lock-file get-lock-file (or/c path-string? (-> path-string?)) (make-lock-filename filename)]
|
||||
[#:lock-file lock-file (or/c #f path-string?) #f]
|
||||
[#:delay delay (and/c real? (not/c negative?)) 0.01]
|
||||
[#:max-delay max-delay (and/c real? (not/c negative?)) 0.2])
|
||||
any]{
|
||||
|
||||
Obtains a lock for the filename returned from @racket[(get-lock-file)] and then
|
||||
calls @racket[thunk]. When @racket[thunk] returns,
|
||||
Obtains a lock for the filename @racket[lock-file] and then
|
||||
calls @racket[thunk]. The @racket[filename] argument specifies
|
||||
a file path prefix that is only used
|
||||
to generate the lock filename when @racket[lock-file] is @racket[#f].
|
||||
Specifically, when @racket[lock-file] is @racket[#f], then
|
||||
@racket[call-with-file-lock/timeout] uses @racket[make-lock-file-name] to build the
|
||||
lock filename.
|
||||
|
||||
When @racket[thunk] returns,
|
||||
@racket[call-with-file-lock] releases the lock, returning the result of
|
||||
@racket[thunk]. The @racket[call-with-file-lock/timeout] function will retry
|
||||
after @racket[#:delay] seconds and continue retrying with exponential backoff
|
||||
until delay reaches @racket[#:max-delay]. If
|
||||
after @racket[delay] seconds and continue retrying with exponential backoff
|
||||
until delay reaches @racket[max-delay]. If
|
||||
@racket[call-with-file-lock/timeout] fails to obtain the lock,
|
||||
@racket[failure-thunk] is called in tail position. The @racket[kind] argument
|
||||
specifies whether the lock is @racket['shared] or @racket['exclusive]
|
||||
in the sense of @racket[port-try-file-lock?].
|
||||
|
||||
The @racket[filename] argument specifies a file path prefix that is only used
|
||||
to generate the lock filename, when @racket[#:get-lock-file] is not present.
|
||||
The @racket[call-with-file-lock/timeout] function uses a separate lock file to
|
||||
prevent race conditions on @racket[filename], when @racket[filename] has not yet
|
||||
been created. On the Windows platfom, the @racket[call-with-file-lock/timeout]
|
||||
function uses a separate lock file (@racket["_LOCKfilename"]), because a lock
|
||||
on @racket[filename] would interfere with replacing @racket[filename] via
|
||||
@racket[rename-file-or-directory].
|
||||
}
|
||||
|
||||
@examples[
|
||||
|
|
|
@ -1162,7 +1162,7 @@
|
|||
(t:-> -Pathlike ManyUniv))
|
||||
|
||||
(tc-e (call-with-file-lock/timeout #f 'exclusive (lambda () 'res) (lambda () 'err)
|
||||
#:get-lock-file (lambda () "lock")
|
||||
#:lock-file "lock"
|
||||
#:delay .01
|
||||
#:max-delay .2) (one-of/c 'res 'err))
|
||||
|
||||
|
|
|
@ -835,7 +835,7 @@
|
|||
(one-of/c 'shared 'exclusive)
|
||||
(-> a)
|
||||
(-> a)
|
||||
#:get-lock-file (-> -Pathlike) #f
|
||||
#:lock-file (-opt -Pathlike) #f
|
||||
#:delay -Real #f
|
||||
#:max-delay -Real #f
|
||||
a))]
|
||||
|
|
Loading…
Reference in New Issue
Block a user