influx6 / actorkit

Simple yet powerful actor model in golang for message passing based applications [Work in Progress]
MIT License
21 stars 2 forks source link

Mailbox Refactor #13

Open influx6 opened 5 years ago

influx6 commented 5 years ago

The current implementation of Mailbox interface and it's implementation and their Envelope type, are abit under-designed, the interface leaks some methods from implementation causing Interface Poisoning which is bad design after much thought, we need to at a suitable time, reconsider a refactor of both the interface and it's implementation (the default MailboxImpl).

I personal feel that the underline mechanism for giving mailbox should be pulled based initially, because a pull based system can easily be converted to a push based system based on some wrapping. I am also favorable to the the idea of reactive streams, so we should consider such in our refactoring.

// Mailbox is a one-subscription publisher of envelope messages.
type Mailbox interface {
  Subscribe (MailSubscriber) (MailSubscription, error)
}

type MailSubscription interface{
   Stop()
   Next(batch int) error
}

type MailSubscriber interface {
  Stopped()
  Error(error)
  Completed()
  Next(EnvelopeMessage) error
}

type EnvelopeMessage interface{
  Encode(encoder EnvelopeEncoder)  error

  Meta(string) (interface{}, error)
  Payload() interface{}
  Ref() string
  Epoch() int64
}

type EnvelopeEncoder interface{
  EncodeRef(string) error
  EncodeEpoch(int64) error
  EncodePayload(interface{}) error
  EncodeMeta(string, interface{}) error
}

Think more on this.