vendredi 18 mars 2016

pattern for switch roles "sender/receiver" with scala

For the first review very simple task. I have two objects A and B

Next algorithm:

  1. Run scheduler
  2. A - send message to B and B receive message
  3. After 10 seconds A and B need to swap
  4. B - send message to A
  5. ...

So, each 10 seconds need to swap sender and receiver.

This is very rude code, just for example

    swap(A, B)
      val res = send(A)

      Thread.sleep(10000)
      res.cancel

      swap(A, B)
      val res2 = send(B)

      Thread.sleep(10000)
      res2.cancel
...

Do you know some approach or pattern for this aim?

Thanks.

BR!

Aucun commentaire:

Enregistrer un commentaire