Store that for every call acquires a lock before executing it on the requested resource, and releases it afterwards. In case the request returns a Representation the lock will only be released when the data stream is finished. Similarly, for write operations the lock will be maintained as long as the incoming data stream is being read.

For auxiliary resources the lock will be applied to the subject resource. The actual operation is still executed on the auxiliary resource.

Implements

Constructors

Properties

logger: Logger = ...

Methods

  • Wraps a representation to make it reset the timeout timer every time data is read.

    Type Parameters

    Parameters

    • representation: T

      The representation to wrap

    • maintainLock: (() => void)

      Function to call to reset the timer.

        • (): void
        • Returns void

    Returns T

  • Acquires a lock that is only released when all data of the resulting representation data has been read, an error occurs, or the timeout has been triggered. The resulting data stream will be adapted to reset the timer every time data is read.

    In case the data of the resulting stream is not needed it should be closed to prevent a timeout error.

    Parameters

    Returns Promise<Representation>

  • Acquires a write lock that is held until the operation completes. The input representation is adapted to reset the timer every time data is read.

    Type Parameters

    Parameters

    • identifier: ResourceIdentifier

      Identifier that should be locked.

    • inputRepresentation: T

      Representation to pass to the write operation.

    • whileLocked: ((representation: T) => Promise<TResult>)

      Function to be executed while the resource is locked.

        • (representation): Promise<TResult>
        • Parameters

          • representation: T

          Returns Promise<TResult>

    Returns Promise<TResult>

  • Returns a promise that resolve when the source stream is finished, either by ending or emitting an error. In the case of an error the stream will be destroyed if it hasn't been already.

    Parameters

    • source: Readable

      The input stream.

    Returns Promise<void>