Details

    • Type: Sub-task
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      In this example:

            FunctionalMap.ReadOnlyMap<String, String> readOnlyMap = CreateFunctionalMaps.ro();
            FunctionalMap.WriteOnlyMap<String, String> writeOnlyMap = CreateFunctionalMaps.wo();
            FunctionalMap.ReadWriteMap<String, String> readWriteMap = CreateFunctionalMaps.rw();
      
            // `written` is a ReadEntryView of the written entry
            try(AutoCloseable handler = writeOnlyMap.listeners().onWrite(written ->
                  System.out.printf("Written (via onWrite): %s%n", written.get()))) {
               Map<String, String> entries = new HashMap<>();
               entries.put("key1", "value1");
               entries.put("key2", "value2");
      
               writeOnlyMap.evalMany(entries, (v, writeView) -> writeView.set(v))
                  .get(); // Wait for completable future
            }
      
            AutoCloseable writeCloseHandler = writeOnlyMap.listeners().add(new WriteListener<String, String>() {
               @Override
               public void onWrite(ReadEntryView<String, String> written) {
                  System.out.printf("Written (via add): %s%n", written.get());
               }
            });
      
            CompletableFuture<Void> f0 = writeOnlyMap.eval("key1", view -> view.set("new-value1"));
            CompletableFuture<Void> f1 = f0.thenAccept(ignore ->
               writeOnlyMap.eval("key2", view -> view.set("new-value2")));
            CompletableFuture<Void> f2 = f1.thenAccept(ignore -> {
               try {
                  writeCloseHandler.close();
               } catch (Exception e) {
                  e.printStackTrace();  // TODO: Customise this generated block
               }
            });
            f2.get(); // Wait for completable future
      

      The output is:

      Written (via onWrite): value1
      Written (via onWrite): value2
      Written (via add): new-value1
      

      Even though the listener is closed after the 2nd new value has been modified, it seems like the close might get ahead somehow.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  galder.zamarreno Galder ZamarreƱo
                  Reporter:
                  galder.zamarreno Galder ZamarreƱo
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: