@widergy/polling-handling
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Polling Handling Logo

WidergyWeb PackageSize semantic-release

< Hello! can you give me the user data?
> Hi, I don't have that information, but my friend 83abb91c-31f0-4be6-9b8b-88cbf716c can get it for you.
< Mmm... ok.. Hey 83abb91c-31f0-4be6-9b8b-88cbf716c can you give me the user data?
> Processing
< 🤔 Ok ... now?
> Processing
< 🤔 Ok ... now?
> Processing
< 😒 now?
> OK! { userInfo: ... }
< Great! 😁

Installing

npm install --save @widergy/polling-handling

yarn add @widergy/polling-handling

Basic usage

On application starts

import Polling from '@widergy/polling-handling';

class App extends Component {
  componentDidMount = () => {
    Polling.init('Polling endpoint base url, for example: http://apibaseurl.com/api/v1/async_request/jobs/');
  ....

When you need to consume a service with polling

import Polling from '@widergy/polling-handling';

// Service that triggers async worker generation 
const someService = parameters => api.get('/some_endpoint', parameters);

....
// When we need to consume that service, and poll the async worker to obtain info:
const response = await Polling.handle(someService(parameters));

Interface

Input

Polling.init(baseUrl)

  • baseUrl (Required): Endpoint base for all async jobs, then handle concats job id to this url.

Polling.handle(originalRequest, timeout)

  • originalRequest (Required): Api call that returns job code for poll.

  • timeout (Optional): For override the default timeout value (60000 milliseconds).

Output

If requests fails returns a response object with two keys:

  • error: Complete error details from api answer.
  • status: Status code from api answer.

If request finish ok, a response object with only one key:

  • data: Complete information from api answer.

License

MIT © Widergy

Readme

Keywords

Package Sidebar

Install

npm i @widergy/polling-handling

Weekly Downloads

148

Version

2.1.0

License

MIT

Unpacked Size

12.8 kB

Total Files

5

Last publish

Collaborators

  • widergy.npm
  • guidodinatale
  • santicamm
  • alcurvelo
  • fiozzoli
  • sgulino
  • gmlipina