Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aneldev/dyna-try
https://github.com/aneldev/dyna-try
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/aneldev/dyna-try
- Owner: aneldev
- License: mit
- Created: 2022-01-14T18:04:54.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-25T09:59:15.000Z (almost 3 years ago)
- Last Synced: 2024-10-05T12:36:43.259Z (about 1 month ago)
- Language: JavaScript
- Size: 178 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dynaTry with timeout
**Example**
Suppose we have this api get method:
```
const getPerson = (id: string): Promise => {
...
}
```Let's try to load this within 5000 seconds
```
dynaTry({
timeout: 5000,
try: () => getPerson('ID400232'),
})
.then(person => {
// Do somthing with this person
})
.catch(error => {
// Call for getPerson's errors
// or due to timeout.
});
```Let's have specific error for the timeout.
```
dynaTry({
timeout: 5000,
try: () => getPerson('ID400232'),
timeoutError: new Error('Client timeout'),
})
.then(person => {
// Do somthing with this person
})
.catch(error => {
// Called for getPerson's errors
// In case of timeout the "Client timeout" will be here
});
```# API
```
dynaTry = (
args: {
try: () => Promise; // The timedout promise
timeout: number; // Timeout in ms
timeoutError?: IDynaError | Error; // Custom timeout error
},
): Promise // dynaTry can resolves value
```By default, this error is returned in timeout error.
```
dynaError({
code: 600408,
message: `Try timed out (${timeout}ms)`,
})
```Where is the same as...
```
new Error(`Try timed out (${timeout}ms)`);
```
but without the `code`.