FileSystem.File.open

New in package 168

Syntax

file.open( [ params ] );

Description

Opens the file in exclusive mode and keeps it open until the end of the current request or task.
Concurrent reading from the same file is allowed.
Concurrent writing to the same file fails.

Returns the same FileSystem.File object.

Parameters

Parameter Type Description
params.timeoutSeconds Number The number of seconds to wait before open times out and fails, 0 or null fails immediately. Default: 0.

Examples

Generally, the need to explicitly open / "lock" files revolves around the interceding update scenario problem:

  • task/request 1 loads "state"
  • task/request 2 loads "state"
  • task/request 1 updates "state"
  • task/request 2 updates "state", thus overriding task/request 1 updates

Case 1:

  • tasks 1 and 2 are polling an external service
  • only want records changed since the last poll
  • store lastPolled datetime
  • no need to complicate it, OK for the task 2 to fail

Case 2:

  • same as Case 1, but done on user request
  • not desirable to fail
  • make the request 2 wait

Case 3:

  • similar to Case 1 or 2, but want to have other concurrent "reader" requests
  • for example, just displaying the "lastPolled" on the form
  • keep locking writers, let concurrent readers to access the "state":

Case 4:

  • other ways to concurrently write to the file should not be allowed
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.