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

Internal framework to increase velocity of reactive streams implementation

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Unknown Unknown
    • None
    • 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?

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: