猫鼬:功能“一次" [英] Mongoose: the function "once"

查看:89
本文介绍了猫鼬:功能“一次"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在猫鼬的入门"中( http://mongoosejs.com/docs/index.html ),其中有一个使用函数once的示例:

In the "Getting Started" of Mongoose (http://mongoosejs.com/docs/index.html) there is an example that use the function once:

db.once('open', function callback () {
  // yay!
});

,但是在官方文档中我找不到对函数once的任何引用( http://mongoosejs.com/docs/api.html ).

but in the official documentation I don't find any reference to function once (http://mongoosejs.com/docs/api.html).

此功能的含义是什么?

推荐答案

猫鼬连接是 EventEmitter类.从文档中:

A Mongoose connection is an instance of EventEmitter class. From the documentation:

为事件添加一次侦听器.此侦听器仅被调用 下次触发该事件,然后将其删除.

Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.

这篇关于猫鼬:功能“一次"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆