• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript bluebird.method函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中bluebird.method函数的典型用法代码示例。如果您正苦于以下问题:TypeScript method函数的具体用法?TypeScript method怎么用?TypeScript method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了method函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: APIMethod

export function APIMethod(fn: (...args: any[]) => any): Function {
  let method = Promise.method(fn);

  return (request: express.Request, response: express.Response) => {
    return method.call(this, request, response).then((res: Object) => {
      response.status(200).json(res);
    }).catch(AuthError, (err) => {
      response.status(err.code).json(err.message);
    }).catch(APIError, (err) => {
      response.status(err.code).json(err.message);
    }).catch(mongoose.Error, (err) => {
      let errors = {};
      // _.each(err.errors, (error, field) => {
      //   errors[field] = error.message;
      // });
      response.status(400).json(errors);
    }).catch(jwt.JsonWebTokenError, (err) => {
      console.error(err.stack);
      response.status(401).json(err);
    }).catch((err) => {
      console.error(err.stack);
      response.status(500).json(err.stack);
    });
  }
}
开发者ID:serioga-ninja,项目名称:blog-project,代码行数:25,代码来源:api-method.ts


示例2: Function

      dropPromise = Promise.mapSeries(JSON.parse(row.filters), (filter: string) => {
        let fnBody = filter.trim()
        if (!/^return /i.test(fnBody)) {
          fnBody = 'return ' + fnBody
        }

        const fn = new Function('bp', 'userId', 'platform', fnBody)
        return Promise.method(fn)(bp, row.userId, row.platform)
      }).then(values => {
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:9,代码来源:daemon.ts


示例3: function

 return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
   let fn: Function = descriptor.value;
   descriptor.value = Promise.method((...args) => {
     let req: interfaces.MyRequest = args[0];
     if (!req.params[idAttribute]) {
       throw new MiddlewareError('Id attribute doesn\'t set.');
     }
     return fn.apply(target, args);
   })
 };
开发者ID:serioga-ninja,项目名称:blog-project,代码行数:10,代码来源:api.middleware.ts


示例4: MiddlewareMethod

export function MiddlewareMethod(fn: (...args: any[]) => any): Function {
  let method = Promise.method(fn);

  return (request: express.Request, response: express.Response, next: NextFunction) => {
    return method.call(this, request, response, next)
      .catch(function (err: Error) {
        console.error(err.stack);
        response.status(400).json(err.message);
      });
  }
}
开发者ID:serioga-ninja,项目名称:blog-project,代码行数:11,代码来源:api-method.ts


示例5:

fooProm = Bluebird.attempt(() => {
    if (fooProm) {
        return fooProm;
    }
    return foo;
});

// - - - - - - - - - - - - - - - - -

fooProm = Bluebird.attempt(() => {
	return fooThen;
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

asyncfunc = Bluebird.method(() => {});
{
	const noArg: () => Bluebird<void> = Bluebird.method(() => {});
	const oneArg: (x1: number) => Bluebird<void> = Bluebird.method((x1: number) => {});
	const twoArg: (x1: number, x2: string) => Bluebird<void> = Bluebird.method((x1: number, x2: string) => {});
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

fooProm = Bluebird.resolve(foo);
fooProm = Bluebird.resolve(fooThen);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

voidProm = Bluebird.reject(reason);
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:30,代码来源:bluebird-tests.ts


示例6: async

export default async (botId: string, bp: SDK, db: Database) => {
  const emitChanged = _.throttle(() => {
    bp.realtime.sendPayload(bp.RealTimePayload.forAdmins('broadcast.changed', {}))
  }, 1000)

  const _sendBroadcast = Promise.method((botId, row) => {
    let dropPromise = Promise.resolve(false)

    if (row.filters) {
      dropPromise = Promise.mapSeries(JSON.parse(row.filters), (filter: string) => {
        let fnBody = filter.trim()
        if (!/^return /i.test(fnBody)) {
          fnBody = 'return ' + fnBody
        }

        const fn = new Function('bp', 'userId', 'platform', fnBody)
        return Promise.method(fn)(bp, row.userId, row.platform)
      }).then(values => {
        return _.some(values, v => {
          if (!_.isBoolean(v)) {
            bp.logger.warn('Filter returned something other ' + 'than a boolean (or a Promise of a boolean)')
          }

          return typeof v !== 'undefined' && v !== null && v !== true
        })
      })
    }

    return dropPromise.then(async drop => {
      if (drop) {
        bp.logger.debug(`Drop sending #${row.scheduleId} to user: ${row.userId}. Reason = Filters`)
        return
      }

      const content = await bp.cms.getContentElement(botId, row.text)

      return bp.events.sendEvent(
        bp.IO.Event({
          botId,
          channel: row.platform,
          target: row.userId,
          type: 'text',
          direction: 'outgoing',
          payload: content.formData
        })
      )
    })
  })

  const trySendBroadcast = async (broadcast, { scheduleUser, scheduleId }) => {
    await retry(() => _sendBroadcast(botId, broadcast), {
      max_tries: 3,
      interval: 1000,
      backoff: 3
    })

    await db.deleteBroadcastOutbox(scheduleUser, scheduleId)

    await db.increaseBroadcastSentCount(scheduleId)
  }

  const handleFailedSending = async (err, scheduleId) => {
    bp.logger.error(`Broadcast #${scheduleId}' failed. Broadcast aborted. Reason: ${err.message}`)

    bp.notifications.create(botId, {
      botId,
      level: 'error',
      message: 'Broadcast #' + scheduleId + ' failed.' + ' Please check logs for the reason why.'
    })

    await db.updateErrorField(scheduleId)

    await db.deleteBroadcastOutboxById(scheduleId)
  }

  async function scheduleToOutbox(botId) {
    const { schedulingLock } = await bp.kvs.get(botId, 'broadcast/lock/scheduling')

    if (!db.knex || schedulingLock) {
      return
    }

    const inFiveMinutes = moment()
      .add(5, 'minutes')
      .toDate()
    const endOfDay = moment(inFiveMinutes)
      .add(14, 'hours')
      .toDate()

    const upcomingFixedTime = db.knex.date.isAfter(inFiveMinutes, 'ts')
    const upcomingVariableTime = db.knex.date.isAfter(endOfDay, 'date_time')

    await bp.kvs.set(botId, 'broadcast/lock/scheduling', { schedulingLock: true })

    const schedules = await db.getBroadcastSchedulesByTime(botId, upcomingFixedTime, upcomingVariableTime)

    await Promise.map(schedules, async schedule => {
      const timezones = await db.getUsersTimezone()

      await Promise.mapSeries(timezones, async tz => {
//.........这里部分代码省略.........
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:101,代码来源:daemon.ts


示例7: Function

const _sendBroadcast = Promise.method(row => {
  let dropPromise = Promise.resolve(false)

  if (row.filters) {
    dropPromise = Promise.mapSeries(JSON.parse(row.filters), filter => {
      let fnBody = filter.trim()
      if (!/^return /i.test(fnBody)) {
        fnBody = 'return ' + fnBody
      }

      const fn = new Function('bp', 'userId', 'platform', fnBody)
      return Promise.method(fn)(bp, row.userId, row.platform)
    }).then(values => {
      return _.some(values, v => {
        if (v !== true && v !== false) {
          bp.logger.warn('Filter returned something other ' + 'than a boolean (or a Promise of a boolean)')
        }

        return typeof v !== 'undefined' && v !== null && v !== true
      })
    })
  }

  return dropPromise.then(drop => {
    if (drop) {
      bp.logger.debug(`Drop sending #${row.scheduleId} to user: ${row.userId}. Reason = Filters`)
      return
    }
    return bp.renderers.sendToUser(row.userId, '#!' + row.text)
  })
})
开发者ID:seffalabdelaziz,项目名称:botpress,代码行数:31,代码来源:daemon.ts



注:本文中的bluebird.method函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bluebird.onPossiblyUnhandledRejection函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bluebird.mapSeries函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap