From e4160c684dbeaf19628ee014013f2e3a98133760 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 11 Jul 2022 11:12:32 +0100 Subject: [PATCH] Docs: add timeout example --- docs/api-output.md | 14 ++++++++++++++ lib/output.js | 11 +++++++++++ src/common.cc | 1 - 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/api-output.md b/docs/api-output.md index 10650eb2..5601c8df 100644 --- a/docs/api-output.md +++ b/docs/api-output.md @@ -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 +### 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** **Meta** diff --git a/lib/output.js b/lib/output.js index 6f46ce6c..334a55dc 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1050,6 +1050,17 @@ function tile (options) { * The clock starts when libvips opens an input image for processing. * 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 * * @param {Object} options diff --git a/src/common.cc b/src/common.cc index 924353c7..f567080c 100644 --- a/src/common.cc +++ b/src/common.cc @@ -638,7 +638,6 @@ namespace sharp { Event listener for progress updates, used to detect 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) { vips_image_set_kill(im, TRUE); vips_error("timeout", "%d%% complete", progress->percent);