Home Reference Source
import Geis from 'geis/es6/Geis.js'
public class | source

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

assign(props: Object): Geis

assigns properties to the Geis instance

public

returns attributes for a given Geis update

public

clone(): Geis

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

kill(): null

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(replacer: Function): Promise

replace Query for replacing a lock instance in REQL

public

obtains a lock and then runs an unary function that receives a done callback it also transparently handles functions that return a {Promise}

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

update(updater: Function): Promise

atomic update Query for a lock update REQL operation

Static Public Methods

public static create(): Promise source

creates a new Geis instance

Return:

Promise

Public Constructors

public constructor(key: <type>, options: <type>): Promise<Geis> source

constructor for a Geis class

Params:

NameTypeAttributeDescription
key <type>

The lock key

options <type>

options for the lock

Return:

Promise<Geis>

a Promise object that resolves to a ready Geis instance

Throw:

Invalid_Argument

thrown when passing in arguments that do not match

Public Members

public config: Object source

stores config like table name

public locked: Boolean source

stores the state of the locking mechanism

public name: String source

the default namespace for this lock

public r: REQL source

shorter reference to the raw REQL object

public table: Thinky:Table source

The table where this instance's locks live This should be consistent across application instances

public thinky: Thinky source

the Thinky instance to use for our Locks

Public Methods

public acquire(): Promise<Geis> source

polls until the instance obtains a lock

Return:

Promise<Geis>

public assign(props: Object): Geis source

assigns properties to the Geis instance

Params:

NameTypeAttributeDescription
props Object

The props

Return:

Geis

this

public attributes(): Object source

returns attributes for a given Geis update

Return:

Object

{ description_of_the_return_value }

public clone(): Geis source

Create a new instance of the object with same properties than original.

Return:

Geis

public find(): Promise source

fetches the lease for this Geis instance from RethinkDB

Return:

Promise

public genToken(): Promise<String> source

generates a unique token on the RethinkDB instance

Return:

Promise<String>

public kill(): null source

kills the thinky instance, primarily used for testing cleanup, unlikely to needed in production

Return:

null

public nextExpiry(): Integer source

gets the next closests expiry timestamp in MS

Return:

Integer

Return Properties:

NameTypeAttributeDescription
nextExpiry Integer

public ready(): Promise source

convenience method for determining if the Table is ready for queries

Return:

Promise

public release(): Promise<Array<Geis, Array>> source

releases the lock on the current instance

Return:

Promise<Array<Geis, Array>>

public replace(replacer: Function): Promise source

replace Query for replacing a lock instance in REQL

Params:

NameTypeAttributeDescription
replacer Function

function that implements the REQL replace

Return:

Promise

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:

NameTypeAttributeDescription
fn Function

the function to run after a lock is obtained

Return:

Promise

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

Return:

Promise<Array<Geis, Array>>

Throw:

Lock_Lost

thrown when attempting to touch a lease that has already expired

Lock_Not_Owned

thrown when attempting to touch a lease that is not owned by this instance

public tryLock(): Promise<Array<Geis, Object>> source

tries to attain a lease on the current instance

Return:

Promise<Array<Geis, Object>>

public update(updater: Function): Promise source

atomic update Query for a lock update REQL operation

Params:

NameTypeAttributeDescription
updater Function

function to use as a REQL update

Return:

Promise