

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# 事件(Event)67事件是开发过程中经常使用到的功能,我们经常利用它来做一些解耦的操作。如:更新了用户信息,其他需要更新相关信息的操作自行监听更新等89## 新建监听1011```ts12import { Provide, Scope, ScopeEnum } from "@midwayjs/core";13import { CoolEvent, Event } from "@cool-midway/core";1415/**16 * 接收事件17 */18@CoolEvent()19export class DemoEvent {20 /**21 * 根据事件名接收事件22 * @param msg23 * @param a24 */25 @Event("updateUser")26 async updateUser(msg, a) {27 console.log("ImEvent", "updateUser", msg, a);28 }29}30```3132## 发送事件3334```ts35import { Get, Inject, Provide } from "@midwayjs/core";36import {37 CoolController,38 BaseController,39 CoolEventManager,40} from "@cool-midway/core";4142/**43 * 事件44 */45@CoolController()46export class DemoEventController extends BaseController {47 @Inject()48 coolEventManager: CoolEventManager;4950 /**51 * 发送事件52 */53 @Get("/send")54 public async send() {55 this.coolEventManager.emit("updateUser", { a: 1 }, 12);56 }57}58```5960## 多进程通信6162当你的项目利用如`pm2`等工具部署为 cluster 模式的时候,你的项目会有多个进程,这时候你的事件监听和发送只会在当前进程内有效,如果你需要触发到所有或者随机一个进程,需要使用多进程通信,这里我们提供了一个简单的方式来实现多进程通信。6364需要根据你的业务需求来使用该功能!!!6566```ts67import { Get, Inject, Provide } from "@midwayjs/core";68import {69 CoolController,70 BaseController,71 CoolEventManager,72} from "@cool-midway/core";7374/**75 * 事件76 */77@Provide()78@CoolController()79export class DemoEventController extends BaseController {80 @Inject()81 coolEventManager: CoolEventManager;8283 @Post("/global", { summary: "全局事件,多进程都有效" })84 async global() {85 await this.coolEventManager.globalEmit("demo", false, { a: 2 }, 1);86 return this.ok();87 }88}89```9091**globalEmit**9293```ts94/**95 * 发送全局事件96 * @param event 事件97 * @param random 是否随机一个98 * @param args 参数99 * @returns100 */101globalEmit(event: string, random?: boolean, ...args: any[])102```103
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| cool-team-official/cool-admin-midway.cursor/rules/authority.mdc · 3.3k | Cursor rules | security | 54/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/cache.mdc · 3.3k | Cursor rules | no sections | 58/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/controller.mdc · 3.3k | Cursor rules | api | 46/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/db.mdc · 3.3k | Cursor rules | setupdatabase | 62/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/module.mdc · 3.3k | Cursor rules | no sections | 50/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/service.mdc · 3.3k | Cursor rules | database | 54/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/socket.mdc · 3.3k | Cursor rules | no sections | 58/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/task.mdc · 3.3k | Cursor rules | style | 58/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/tenant.mdc · 3.3k | Cursor rules | no sections | 50/100 | today | |
| cool-team-official/cool-admin-midway.cursorrules · 3.3k | .cursorrules | no sections | 39/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 46 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/cool-team-official-cool-admin-midway-cursor-rules-event)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.