/**
 * 普通函数包装为promise风格函数
 * @param {Function} fn 
 * @returns {Promise<any>} 返回一个promise
 */
export const normalToPromise = (fn) => {
  const tag = Object.prototype.toString.call(fn);
  if (tag !== "[object Function]" && tag !== "[object AsyncFunction]") return fn;
  return (...args) => {
    return new Promise((resolve, reject) => {
      try {
        const result = fn(...args);
        resolve(result);
      } catch (error) {
        reject(error);
      }
    });
  };
};