import { isPromise, noop } from ".";
function callInterceptor(options) {
  const { interceptor, args, done, canceled } = options;
  if (interceptor) {
    const returnVal = interceptor.apply(null, args || []);
    if (isPromise(returnVal)) {
      returnVal.then((value) => {
        if (value) {
          done();
        } else if (canceled) {
          canceled();
        }
      }).catch(noop);
    } else if (returnVal) {
      done();
    } else if (canceled) {
      canceled();
    }
  } else {
    done();
  }
}
export {
  callInterceptor
};
