mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Docs: add timeout example
This commit is contained in:
parent
905518fab0
commit
e4160c684d
@ -589,6 +589,20 @@ Time spent waiting for a libuv thread to become available is not included.
|
|||||||
|
|
||||||
* `options.seconds` **[number][12]** Number of seconds after which processing will be stopped
|
* `options.seconds` **[number][12]** Number of seconds after which processing will be stopped
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Ensure processing takes no longer than 3 seconds
|
||||||
|
try {
|
||||||
|
const data = await sharp(input)
|
||||||
|
.blur(1000)
|
||||||
|
.timeout({ seconds: 3 })
|
||||||
|
.toBuffer();
|
||||||
|
} catch (err) {
|
||||||
|
if (err.message.includes('timeout')) { ... }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
@ -1050,6 +1050,17 @@ function tile (options) {
|
|||||||
* The clock starts when libvips opens an input image for processing.
|
* The clock starts when libvips opens an input image for processing.
|
||||||
* Time spent waiting for a libuv thread to become available is not included.
|
* Time spent waiting for a libuv thread to become available is not included.
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Ensure processing takes no longer than 3 seconds
|
||||||
|
* try {
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .blur(1000)
|
||||||
|
* .timeout({ seconds: 3 })
|
||||||
|
* .toBuffer();
|
||||||
|
* } catch (err) {
|
||||||
|
* if (err.message.includes('timeout')) { ... }
|
||||||
|
* }
|
||||||
|
*
|
||||||
* @since 0.29.2
|
* @since 0.29.2
|
||||||
*
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
|
@ -638,7 +638,6 @@ namespace sharp {
|
|||||||
Event listener for progress updates, used to detect timeout
|
Event listener for progress updates, used to detect timeout
|
||||||
*/
|
*/
|
||||||
void VipsProgressCallBack(VipsImage *im, VipsProgress *progress, int *timeout) {
|
void VipsProgressCallBack(VipsImage *im, VipsProgress *progress, int *timeout) {
|
||||||
// printf("VipsProgressCallBack progress=%d run=%d timeout=%d\n", progress->percent, progress->run, *timeout);
|
|
||||||
if (*timeout > 0 && progress->run >= *timeout) {
|
if (*timeout > 0 && progress->run >= *timeout) {
|
||||||
vips_image_set_kill(im, TRUE);
|
vips_image_set_kill(im, TRUE);
|
||||||
vips_error("timeout", "%d%% complete", progress->percent);
|
vips_error("timeout", "%d%% complete", progress->percent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user