How to use make-cancellable-promise - 5 common examples

To help you get started, we’ve selected a few make-cancellable-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wojtekmaj / react-pdf / src / Document.jsx View on Github external
return { pdf: null };
    });

    const { options, onLoadProgress, onPassword } = this.props;

    try {
      // If another loading is in progress, let's cancel it
      cancelRunningTask(this.runningTask);

      const loadingTask = pdfjs.getDocument({ ...source, ...options });
      loadingTask.onPassword = onPassword;
      if (onLoadProgress) {
        loadingTask.onProgress = onLoadProgress;
      }
      const cancellable = makeCancellable(loadingTask.promise);
      this.runningTask = cancellable;
      const pdf = await cancellable.promise;

      this.setState((prevState) => {
        if (prevState.pdf && prevState.pdf.fingerprint === pdf.fingerprint) {
          return null;
        }

        return { pdf };
      }, this.onLoadSuccess);
    } catch (error) {
      this.onLoadError(error);
    }
  }
github wojtekmaj / react-pdf / src / Page / AnnotationLayer.jsx View on Github external
loadAnnotations = async () => {
    const { page } = this.props;

    try {
      const cancellable = makeCancellable(page.getAnnotations());
      this.runningTask = cancellable;
      const annotations = await cancellable.promise;
      this.setState({ annotations }, this.onLoadSuccess);
    } catch (error) {
      this.onLoadError(error);
    }
  }
github wojtekmaj / react-pdf / src / Outline.jsx View on Github external
loadOutline = async () => {
    const { pdf } = this.props;

    this.setState((prevState) => {
      if (!prevState.outline) {
        return null;
      }
      return { outline: null };
    });

    try {
      const cancellable = makeCancellable(pdf.getOutline());
      this.runningTask = cancellable;
      const outline = await cancellable.promise;
      this.setState({ outline }, this.onLoadSuccess);
    } catch (error) {
      this.onLoadError(error);
    }
  }
github wojtekmaj / react-pdf / src / Page / TextLayer.jsx View on Github external
loadTextItems = async () => {
    const { page } = this.props;

    try {
      const cancellable = makeCancellable(page.getTextContent());
      this.runningTask = cancellable;
      const { items: textItems } = await cancellable.promise;
      this.setState({ textItems }, this.onLoadSuccess);
    } catch (error) {
      this.onLoadError(error);
    }
  }
github wojtekmaj / react-pdf / src / Page.jsx View on Github external
const pageNumber = this.getPageNumber();

    if (!pageNumber) {
      return;
    }

    this.setState((prevState) => {
      if (!prevState.page) {
        return null;
      }
      return { page: null };
    });

    try {
      const cancellable = makeCancellable(pdf.getPage(pageNumber));
      this.runningTask = cancellable;
      const page = await cancellable.promise;
      this.setState({ page }, this.onLoadSuccess);
    } catch (error) {
      this.setState({ page: false });
      this.onLoadError(error);
    }
  }

make-cancellable-promise

Make any Promise cancellable.

MIT
Latest version published 6 months ago

Package Health Score

73 / 100
Full package analysis

Popular make-cancellable-promise functions