Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5082

Internal framework to increase velocity of reactive streams implementation

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Recent work with async code added a few async helper methods, which developed into a candidate API for writing async code in the driver. The team should evaluate whether this API might be used for writing async code.

      If it fits our needs, this API might be used to simplify new async code. It might remove the need to switch to Project Reactor for our async code. We may need a document or examples that would help us to evaluate and determine how to proceed.

      For example, much of our async code looks like this:

      try {
          plain(11)
          async(1, c1 -> {
              try {
                  plain(22);
                  async(2, callback)
              } catch (...) { ...callback... }
          })
      } catch (...) { ...callback... }
      

      There is substantial boilerplate, especially in larger examples. The nesting is also difficult to read. It corresponds to the following sync code, where "plain" is a plain sync method, and "sync" is a sync method that must be converted to an async method when writing the above corresponding async code.

      plain(11);
      sync(1);
      plain(22);
      sync(2);
      

      The revised API proposes the following mechanism:

      beginAsync().thenRun(c -> {
          plain(11);
          async(1, c);
      }).thenRun(c -> {
          plain(22);
          async(2, c);
      }).finish(callback);
      

      Other examples can be found here.

            Assignee:
            maxim.katcharov@mongodb.com Maxim Katcharov
            Reporter:
            maxim.katcharov@mongodb.com Maxim Katcharov
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: