Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

individual responses instead of summary for .forward() #5

Open
siddo420 opened this issue Oct 16, 2015 · 2 comments
Open

individual responses instead of summary for .forward() #5

siddo420 opened this issue Oct 16, 2015 · 2 comments

Comments

@siddo420
Copy link

Currently, .forward() returns a single info object which is a summary of responses for all sparks. It does not indicate which particular spark(s) from the input list were sent to successfully.

Here is how it should be:

['L1mXUWv', 'L1mXUX9', '234fwfrewrw423#%#$']

So, if above is the input list of sparks and assuming that 3rd item is invalid/disconnected/non-existent, the output should be similar to:

[ 'ok','ok',null ]

So, client could store the ACKs at some place and re-attempt the ones that failed (for any reason).

Just to be doubly sure, index of results must match the corresponding sparks in input list.

Edit:
Another option is to extend the 'info' object by adding 'sparks' array that is a list of spark(s) where msg was successfully sent.

Example: { ok: true, send: 2, sparks:['L1mXUWv', 'L1mXUX9'] }

@siddo420
Copy link
Author

Here is something that I put together (not tested yet) that actually extends the existing 'info' object by including spark IDs, so we're not breaking anything hopefully.

In omega.js (in parse()):

var result = [],
sparks = undefined;

if (Array.isArray(data.sparks)) {
  sparks = data.sparks;
} else if ('string' === typeof data.sparks && data.sparks) {
  sparks = [data.sparks];
} else {
  sparks = [];
  primus.forEach(function each(spark) {
    sparks.push( spark.id );
  });
}

if ('undefined' !== typeof sparks && Array.isArray(sparks)) {
  sparks.forEach(function each(id) {
    var spark = primus.spark(id);
    if (spark && spark.write( data.msg )) {
      result.push( id );
      called++;
    }
  });
}

FYI: This may be less efficient (in case of broadcast) but is cleaner.

Then, at the end you can send the result like below:

    res.end('{ "ok": true, "send":'+ called +', "sparks":'+JSON.stringify(result)+' }');

result.length can be used instead of called and called++ etc.

@siddo420
Copy link
Author

we need to make similar changes to other files but I seem to have gotten stuck at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant