Geis
the main class that generates a lease
Example:
Geis.create("queue").then( lock => {
//lock is ready to use
})
Static Method Summary
Static Public Methods | ||
public static |
creates a new Geis instance |
Constructor Summary
Public Constructor | ||
public |
constructor(key: <type>, options: <type>): Promise<Geis> constructor for a Geis class |
Member Summary
Public Members | ||
public |
stores config like table name |
|
public |
stores the state of the locking mechanism |
|
public |
the default namespace for this lock |
|
public |
r: REQL shorter reference to the raw REQL object |
|
public |
table: Thinky:Table The table where this instance's locks live This should be consistent across application instances |
|
public |
thinky: Thinky the Thinky instance to use for our Locks |
Method Summary
Public Methods | ||
public |
polls until the instance obtains a lock |
|
public |
assigns properties to the Geis instance |
|
public |
attributes(): Object returns attributes for a given Geis update |
|
public |
Create a new instance of the object with same properties than original. |
|
public |
fetches the lease for this Geis instance from RethinkDB |
|
public |
generates a unique token on the RethinkDB instance |
|
public |
kills the thinky instance, primarily used for testing cleanup, unlikely to needed in production |
|
public |
nextExpiry(): Integer gets the next closests expiry timestamp in MS |
|
public |
convenience method for determining if the Table is ready for queries |
|
public |
releases the lock on the current instance |
|
public |
replace Query for replacing a lock instance in REQL |
|
public |
synchronize(fn: Function): Promise obtains a lock and then runs an unary function that receives a |
|
public |
resets the expiry to 5 seconds in the future for an acquired lock |
|
public |
tries to attain a lease on the current instance |
|
public |
atomic update Query for a lock update REQL operation |
Static Public Methods
Public Constructors
Public Members
public table: Thinky:Table source
The table where this instance's locks live This should be consistent across application instances
Public Methods
public assign(props: Object): Geis source
assigns properties to the Geis instance
Params:
Name | Type | Attribute | Description |
props | Object | The props |
public kill(): null source
kills the thinky instance, primarily used for testing cleanup, unlikely to needed in production
public nextExpiry(): Integer source
gets the next closests expiry timestamp in MS
Return:
Integer |
Return Properties:
Name | Type | Attribute | Description |
nextExpiry | Integer |
public replace(replacer: Function): Promise source
replace Query for replacing a lock instance in REQL
Params:
Name | Type | Attribute | Description |
replacer | Function | function that implements the REQL replace |
public synchronize(fn: Function): Promise source
obtains a lock and then runs an unary function that receives a done
callback
it also transparently handles functions that return a {Promise}
Params:
Name | Type | Attribute | Description |
fn | Function | the function to run after a lock is obtained |
Example:
lock.synchronize( function (done) {
write_to_shared_file(data, function (err, result){
if (err) return done(err) // throws unless caught because we should propogate errors
done(result)
})
})
.catch( err => {
// handle err
})
.then( result => {
// handle success
})
lock.synchronize( function () {
return promised_write_to_shared_file(data)
})
.catch( err => {
// handle error
})
.then( result => {
// handle success
})
public touch(): Promise<Array<Geis, Array>> source
resets the expiry to 5 seconds in the future for an acquired lock
Throw:
thrown when attempting to touch a lease that has already expired |
|
thrown when attempting to touch a lease that is not owned by this instance |