2.1.0 • Published 15 days ago

@widergy/polling-handling v2.1.0

Weekly downloads
182
License
MIT
Repository
github
Last release
15 days ago

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

2.1.0

15 days ago

1.6.2

7 months ago

1.7.0

7 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago