Questions tagged [callable]

A task that returns a result and may throw an exception.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

759 questions
6
votes
1 answer

In PHP, is it more efficient to use a lambda expression for a callable than a string (or array)?

In PHP, some function take a "callable" as an argument, meaning you can specify a function to be executed at some point down the line. One example is array_map. PHP allows you to specify a callable in multiple ways, for example: // as a…
Hanno Fietz
  • 30,799
  • 47
  • 148
  • 234
6
votes
2 answers

How to call the callable function in PHP?

I've one array titled $post_data. I want to pass this array to some function as an argument. Along with this array I've to pass another argument the callable 'function name' as second argument in a function call. I'm not understanding how to achieve…
PHPLover
  • 1
  • 51
  • 158
  • 311
6
votes
2 answers

php print callable function

I'm trying to solve a problem : function f($callable_function){ print_r($callable_function);// doesn't work at all, of course } f(function(){echo "hello World"}); I get the Closure Object element with my print_r function. Is there a way to get…
d3cima
  • 729
  • 1
  • 10
  • 31
6
votes
2 answers

What is callable in Java?

The title pretty much sums it. I want to know the concept and idea of callable . I have read a question here on difference between callable and runnable. but no one show code and give detail what a callable is. I don't want to know the difference…
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
6
votes
0 answers

why does ExecutorService not have invokeAll for Runnable tasks

I noticed that there are submit methods for both Runnable task and Callable task. Why is there only invokeAll for Callable tasks, but no invokeAll for Runnable tasks. Thanks
Jacky
  • 8,619
  • 7
  • 36
  • 40
6
votes
2 answers

java.util.concurrent.ExecutionException: java.lang.NullPointerException Error

The following code snippet doesnt throw any error when executed in a standalone mode. When I deploy this into a web server [implementing a server's interface and added as JAR into classpath], I get java.util.concurrent.ExecutionException:…
Srii
  • 543
  • 3
  • 7
  • 20
6
votes
5 answers

PHP Callable Object as Object Member

I have a class Logger which, among other things has a method Log. As Log is the most common use of the Logger instance, I have wired __invoke to call Log Another class, "Site" contains a member "Log", an instance of Logger. Why would this work: …
James Maroney
  • 3,136
  • 3
  • 24
  • 27
6
votes
2 answers

How I can pass callable object to function as parameter

In c++ standard library almost all algo function takes a callable object as a argument. Now I want to try this thing with my program. I opened the the headers for function like find_if or search_n() but could not understand much about how these…
deeiip
  • 3,319
  • 2
  • 22
  • 33
6
votes
2 answers

Java Concurrency: How can I tell which Future belongs to which Callable during processing?

I have a collection of Callables and a ExecutorService. When I invokeAll, I get back a list of Future objects. How can I tell which Future object mapped to which Callable before the Future completes? I can tell afterwards because the Code: …
MeowCode
  • 1,053
  • 2
  • 12
  • 29
5
votes
0 answers

Mypy thinks @classmethod @property is Callable

Mypy seems to have trouble understanding a property is not a callable method of a class: from abc import abstractmethod from typing import Type class A: pass class B: @abstractmethod @property @classmethod def other_type(cls)…
Dori
  • 1,035
  • 1
  • 12
  • 22
5
votes
2 answers

How to make python typing recognize subclasses as valid types when it expects their parent class?

Here is a minimal example of what I need to do: from typing import Callable, Any class Data: pass class SpecificData(Data): pass class Event: pass class SpecificEvent(Event): pass def detect_specific_event(data:…
Petar Chernev
  • 173
  • 1
  • 7
5
votes
3 answers

CompletableFuture : Invoke a void function asynchronusly

I am trying to implement a database query with retry strategy on certain database exceptions. The code for retry strategy is not very relevant, so I did not include it. As you can see in the code below - I have written a retryCallable which takes…
maddie
  • 629
  • 10
  • 29
5
votes
1 answer

Deduction of result type of callable

I try to deduce the type of callable template parameter, unfortunately without success: template class A {}; template auto make_A( callable f ) { return A
abraham_hilbert
  • 2,221
  • 1
  • 13
  • 30
5
votes
1 answer

What is the difference between std::invoke and std::function?

Why do we need std::invoke, when we already have std::function? What is the difference between them? Both used to call callable objects. What's the point to add new template?
Ivan Kush
  • 2,958
  • 2
  • 23
  • 39
5
votes
2 answers

Make a Method Which Generates the x and y values of Another Given Function

I have just started to learn about Java Runnables and I have heard of Callables. However, I am very much struggling with this problem. I would like to make a method which takes a function as an argument (whether that be as a Callable, a Runnable, or…
Dylan Siegler
  • 742
  • 8
  • 23