/utils/ping
The ping utility module exports a method to repeat a ping query until a condition is met.
- Source
Methods
(inner) ping(params)
The ping utility method executes the pingQuery method which will repeat at a given interval until a condition is met.
The ping method will create a request url for the ping query from the provided queryparams object.
mapp.utils.ping({
query: 'location_field_value',
responseType: 'text',
successCondition: 'ok',
failCondition: 'failed',
queryparams: {
id: true,
field: 'model_status',
table: 'location_table',
},
interval: 4000,
callback: (response) => {
console.log(response);
},
});
Name | Type | Description |
---|---|---|
params | Object | The parameters object. |
Name | Type | Description |
---|---|---|
params.query | string | The query template for the ping query. |
params.queryparams | Object | Parameters for the ping query. |
- Source
(inner) pingQuery(params) → {Promise}
The pingQuery method will call itself with a timeout until a condition is met.
The method will reject if the response is an error.
The method will resolve if the response matches either the failCondition or the successCondition.
The method will resolve if the callback property is set to false.
If the callback property is a function it will be called with the response and the params object itself as arguments.
Name | Type | Description |
---|---|---|
params | Object | The parameters object. |
Name | Type | Description |
---|---|---|
params.responseType | string | The expected responseType form the ping query. |
params.url | string | The request url for the ping query. |
params.callback | function | Method to be executed with the response and params object as arguments. |
params.successCondition | string | The expected response for a successful ping query. |
params.failCondition | string | The expected response for a failed ping query. |
params.interval | number | The interval in milliseconds between ping queries. |
- Source
A promise that resolves with the response or rejects with an error.
- Type:
- Promise