senecajs / seneca-balance-client

seneca-balance-client
MIT License
18 stars 14 forks source link

Add order matters but should not, right? #35

Closed surfdude75 closed 6 years ago

surfdude75 commented 6 years ago
Seneca().listen(47000).add 'a:1', (args, done) ->
  done null, a: 1
.ready (err) ->
  return console.error err if err?
  Seneca().listen(47001).add 'a:1,cache:true', (args, done) ->
    done null, a:1, cache: true
  .ready (err) ->
    return console.error err if err?
    seneca = Seneca()
    seneca.use('seneca-balance-client')
    seneca.client pin: 'a:1,cache:true', type: 'balance'
    seneca.client pin: 'a:1,cache:true', port: 47001
    seneca.client pin: 'a:1', type: 'balance'
    seneca.client pin: 'a:1', port: 47000
    seneca.act a:1, (err,data) ->
      console.log data
      seneca.act a:1, cache: true, (err,data) ->
        console.log data
        seneca.act a:1, (err,data) ->
          console.log data

Works as expected resulting in:

{ a: 1 } { a: 1, cache: true } { a: 1 }

The following code where I just change the order:

Seneca().listen(47000).add 'a:1', (args, done) ->
  done null, a: 1
.ready (err) ->
  return console.error err if err?
  Seneca().listen(47001).add 'a:1,cache:true', (args, done) ->
    done null, a:1, cache: true
  .ready (err) ->
    return console.error err if err?
    seneca = Seneca()
    seneca.use('seneca-balance-client')
    seneca.client pin: 'a:1', type: 'balance'
    seneca.client pin: 'a:1', port: 47000
    seneca.client pin: 'a:1,cache:true', type: 'balance'
    seneca.client pin: 'a:1,cache:true', port: 47001
    seneca.act a:1, (err,data) ->
      console.log data
      seneca.act a:1, cache: true, (err,data) ->
        console.log data
        seneca.act a:1, (err,data) ->
          console.log data

Does not work as expected resulting in:

{ a: 1 } { a: 1 } { a: 1 }

I study the code and was not able to find a fix working in the plugin.

But I was able to fix adding the strict$ property in pin inside client function in seneca library.

Apparently it do not affect seneca test but fixed this plugin. I am not sure if it can cause side effects.

This problem cause problems in seneca-mesh plugin too, since it depends on this one. It is even moe critical in this case because you do not have control over add order.

Preparing a PR for your evaluation.

Thanks.

Congrats for your great work.

Aloha!

Rafael Sobral

PS: Code above is in coffescript

surfdude75 commented 6 years ago

Here is a related problem example in mesh plugin

https://github.com/senecajs/seneca-mesh/issues/106

Here is the PR

https://github.com/senecajs/seneca/pull/694

rjrodger commented 6 years ago

Thank You!

Great find - fix is now in seneca master