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

Compatibility with primus-callbacks #20

Open
mauron85 opened this issue Oct 31, 2016 · 1 comment
Open

Compatibility with primus-callbacks #20

mauron85 opened this issue Oct 31, 2016 · 1 comment

Comments

@mauron85
Copy link

mauron85 commented Oct 31, 2016

Hi there,

wondering if it's possible to make primus-callbacks work on a substream? It currently works on main stream and I believe it's only about writing implementation for primus-callbacks writeAndWait method.

  /**
   * Write a new message to the streams and wait for response
   *
   * @param {Mixed} msg The data that needs to be written.
   * @param {Func} done nodejs style callback (err, response)
   * @returns {Boolean}
   * @api public
   */
SubStream.prototype.writeAndWait = function write(msg, done) {
  // TODO: implementation here
};

I'll try to implement it myself, but I'm bit lost in how transform works. What does this code actually do?

  /**
   * Write a new message to the streams.
   *
   * @param {Mixed} msg The data that needs to be written.
   * @returns {Boolean}
   * @api public
   */
  SubStream.prototype.write = function write(msg) {
    if (!this.stream) return false;

    this.stream.transforms(this.primus, this, 'outgoing', msg);
    return true;
  };

and when this get invoked?


  /**
   * Actually write the message.
   *
   * @param {Mixed} msg The data that needs to be written.
   * @returns {Boolean}
   * @api private
   */
  SubStream.prototype._write = function write(msg) {
    return this.stream._write({
      substream: this.name,
      args: msg
    });
  };

Thanks

@lpinca
Copy link
Member

lpinca commented Oct 31, 2016

What does this code actually do?

It calls the transforms method on the Spark or the client.

That transforms method runs the registered message transformers and then call SubStream.prototype._write (see the second argument) with the transformed data.

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

2 participants