# Function cancelify

- cancelify<T>(promise, cancelToken, onCancel?): Promise<T>

- Takes an existing promise and makes it cancellable via the given cancel token. If the cancel token is never triggered, then the promise will resolve as normal. However, if the cancel token is triggered and the promise is not yet resolved, then it will be rejected with an instance of Cancellation.

  #### Type Parameters

  - T

  #### Parameters

  - promise: PromiseLike<T>

    The original promise to make cancellable.

  - cancelToken: CancelToken

    The cancellation token obtained from a support/Cancellable!Cancellable.

  - `Optional` onCancel: ((reason: unknown) => void)

    On optional callback to trigger when the promise is about to be canceled.

    - - (reason): void

      - #### Parameters

        - reason: unknown

        #### Returns void

  #### Returns Promise<T>

  A new promise that adds cancellation semantics to the original promise.