Skip to content

functional deferred construction #498

@jknack

Description

@jknack

Deferred API work as callback where we must call resolve or reject method.

{
   get("/deferred", promise(deferred -> {
      deferred.resolve("OK");
   }));
}

This programming model makes perfect sense to integrate reactive/async libraries like rx, reactor, etc... but is kind of verbose for using within an Executor:

{
   executor(new ForkJoinPool());

   get("/deferred", promise(deferred -> {
      deferred.resolve("OK");
   }));
}

When we could just write:

{
   executor(new ForkJoinPool());

   get("/deferred", deferred(() -> {
     return "OK";
   }));
}

If an error occurs while resolving the value, we automatically catch the exception and call reject.

This is just more syntax sugar, no major change is required.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions