question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't use Capture as a return value

See original GitHub issue

By returning Capture (or future thereof) we have the burden to preserve type safety. If the change this we can let the client handle this in a safer and easier way:

Capture<List<String>> capture = Capture.empty();

http.get("/").dispatch(series(),
        on(SUCCESSFUL).call(capture),
        anySeries().call(fail))
        .get(10, SECONDS);

capture.retrieve(); // throws NotReadyException vs EmptyException

Benefits

  • completely type safe
  • no unsafe casts
  • easy to understand for clients
  • API is now 100% callbacks
  • does not even need to be part of the core API (even though it probably will)

This will complete get rid of the problematic of #114.

  • externalize into own module: riptide-capture

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
whiskeysierracommented, Jul 4, 2016

The factory method for that could be in Capture already:

public Future<List<String>> remote() {
    Capture<List<String>> capture = Capture.empty();

    final Future<?> future = http.get("/").dispatch(series(),
            on(SUCCESSFUL).call(capture),
            anySeries().call(fail));

    return capture.adapt(future);
}
0reactions
whiskeysierracommented, Jul 5, 2016

There will be cases where clients want a synchronous response, in those cases a callback-style API is not very user friendly. This is the reason why we have capture in the first place. I see it as a usability extension to make synchronous return values easier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any reason to capture a return-value as an rvalue ...
auto&& means, in a sense, "just make it work, and don't do extra work", and it could deduce to a Foo&& . auto...
Read more >
Lambda expressions (since C++11) - cppreference.com
A lambda expression can use a variable without capturing it if the ... If trailing-return-type is not present, the return type of the ......
Read more >
The Python return Statement: Usage and Best Practices
In this step-by-step tutorial, you'll learn how to use the Python return statement when writing functions. Additionally, you'll cover some good programming ...
Read more >
Returning a Value from a Method (The Java™ Tutorials ...
Within the body of the method, you use the return statement to return the value. Any method declared void doesn't return a value....
Read more >
Closures: Anonymous Functions that Capture Their Environment
We'll first examine h ow we can use closures to capture values from t h e ... a closure wit h out any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found