Giter Site home page Giter Site logo

重构 messenger about egg HOT 15 CLOSED

eggjs avatar eggjs commented on March 29, 2024
重构 messenger

from egg.

Comments (15)

popomore avatar popomore commented on March 29, 2024

可以分开写下,比如 app 应该没有 sendRandom 方法。

app 调用 sendToApp 会怎么样,sendToAgent 同理

sendTo 可以增强一下,如果是 number 是 pid,都要可以指定 target,比如 app master parent,作为上面方法的基础

from egg.

dead-horse avatar dead-horse commented on March 29, 2024

更新了一下。

sendTo 方法的增强是指可以 sendTo('app', action, data) 还是说在指定 pid 的同事还可以加一个 target 的条件(必须满足 pid 相等,target 相同)?

from egg.

popomore avatar popomore commented on March 29, 2024

前一种,process 传的时候有个 to 参数

from egg.

dead-horse avatar dead-horse commented on March 29, 2024

我们需要让应用或者插件开发者感知到 master 和 parent 么?感觉我们现在的这些插件也没出现过向 master 和 parent 发消息的需求啊

from egg.

popomore avatar popomore commented on March 29, 2024

更通用一些,send pid 用的也很少

from egg.

dead-horse avatar dead-horse commented on March 29, 2024

这样?

  • sendTo('parent/master', action, data)
  • sendTo(pid, action, data)

但是 master 和 parent 上其实没有对应的 messenger 实例,应该没法保持这个 action + data 的模型吧?只能 send 一个大的 object 过去?

from egg.

popomore avatar popomore commented on March 29, 2024

master 有的,parent 只有 process

from egg.

popomore avatar popomore commented on March 29, 2024

sendTo('app/agent/master/parent')

from egg.

dead-horse avatar dead-horse commented on March 29, 2024

parent 是我们不能控制的,mater 其实开发者也无法编写任何逻辑,感觉在暴露给用户的 API 上面增加发给他们的方法只会让使用者更疑惑?

from egg.

popomore avatar popomore commented on March 29, 2024

这个还会暴露给插件开发者和核心开发者,比如测试等可能会用到

from egg.

dead-horse avatar dead-horse commented on March 29, 2024

那 sendTo 当做一个内部函数来实现好了?反正应用层不会需要这个方法?

from egg.

popomore avatar popomore commented on March 29, 2024

app 进程

  • broadcast(action, data) 发送给 agent 和所有 app(包括自己)
  • sendToApp(action, data) 发送给所有 app(包括自己)
  • sendToAgent(action, data) 发送给 agent
  • sendTo(pid, action, data) 指定 pid 发送

agent 进程

  • broadcast(action, data) 发送给自己和所有 app
  • sendToApp(action, data) 发送给所有 app
  • sendToAgent(action, data) 发送给自己
  • sendRandom(action, data) 随机发送给一个 app
  • sendTo(pid, action, data) 指定 pid 发送

重新整理下 API @dead-horse

from egg.

atian25 avatar atian25 commented on March 29, 2024

@popomore worker 没启动时, agent 发消息, 这个顺便 warning 下

from egg.

popomore avatar popomore commented on March 29, 2024

这个不是有另外一个 issue 么

from egg.

popomore avatar popomore commented on March 29, 2024

让 master 告诉子进程 pid,然后都 sendTo pid 是不是更好。 暂时不破坏 master 模型了。

from egg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.