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
23
votes
2 answers

Dynamically assigning function implementation in Python

I want to assign a function implementation dynamically. Let's start with the following: class Doer(object): def __init__(self): self.name = "Bob" def doSomething(self): print "%s got it done" % self.name def…
Yarin
  • 173,523
  • 149
  • 402
  • 512
22
votes
4 answers

RestTemplate should be static globally declared?

I am using Java Callable Future in my code. Below is my main code which uses the future and callables - public class TimeoutThread { public static void main(String[] args) throws Exception { ExecutorService executor =…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
22
votes
2 answers

making a class callable in same instance

class Foo(object): def tick(self): print("something") class Bar(object): def __init__(self): self.foo = Foo() def tick(self): #Here's what I do.... self.foo.tick() #here's what my goal would be …
DanielCardin
  • 545
  • 2
  • 8
  • 17
21
votes
7 answers

What does the keyword "callable" do in PHP

To be more exact, the "callable" used in function declaration arguments. like the one below. function post($pattern, callable $handler) { $this->routes['post'][$pattern] = $handler; return $this; } How does it benefit us? why and how do we…
20
votes
1 answer

What is the difference between a function object and a callable object?

I recently saw the presentation about the changes in ECMAScript 5. And there was a slide with this statement: Function vs Callable typeof f === 'function' // → f is Callable ({}).toString.call(f) === '[object Function]' // → f…
Gumbo
  • 643,351
  • 109
  • 780
  • 844
20
votes
5 answers

Java: Parameterized Runnable

Standard Runnable interface has only non-parametrized run() method. There is also Callable interface with call() method returning result of generic type. I need to pass generic parameter, something like this: interface MyRunnable { public…
mschayna
  • 1,300
  • 2
  • 16
  • 32
19
votes
6 answers

timeit ValueError: stmt is neither a string nor callable

I played with timeit in Python, got a weird problem. I define a simple function add. timeit works when I pass add two string parameters. But it raises ValueError: stmt is neither a string nor callable when I pass add two int parameters. >>>…
liang li
  • 253
  • 1
  • 2
  • 9
17
votes
2 answers

executing a method in parallel from a call method

I have a library which is being used by customer and they are passing DataRequest object which has userid, timeout and some other fields in it. Now I use this DataRequest object to make a URL and then I make an HTTP call using RestTemplate and my…
john
  • 11,311
  • 40
  • 131
  • 251
17
votes
5 answers

Understanding Java FixedThreadPool

I am trying to understand how Java FixedThreadPool works in practice, but the docs do not answer my question. Assume a simple scenario like: ExecutorService ES= Executors.newFixedThreadPool(3); List FL; for(int i=1;i<=200;i++){ …
k88074
  • 2,042
  • 5
  • 29
  • 43
16
votes
2 answers

How to code/reference to a PHP callable functions easy to manage for my IDE

When I have to write a reference to a callable function I use the standard syntax of PHP defined as: A PHP function is passed by its name as a string. Any built-in or user-defined function can be used [... omitted...]. A method of an instantiated…
Ivan Buttinoni
  • 4,110
  • 1
  • 24
  • 44
16
votes
2 answers

Python 3: Making a str object callable

I have a Python program that takes user input. I store user input a string variable called "userInput". I want to be able to call the string the user entered... userInput = input("Enter a command: ") userInput() From this, I get the error:…
just_a_programmer
  • 341
  • 1
  • 3
  • 9
16
votes
2 answers

How to declare Callable to execute function returning void in Java?

Suppose I would like to run static method foo asynchronously void foo() throws Exception {...} Since foo throws an exception I would prefer create a Callable and invoke ExecutorService.submit with it to get a Future. Now I wonder how to declare…
Michael
  • 41,026
  • 70
  • 193
  • 341
15
votes
7 answers

How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?

I have a method that I would like to call. However, I'm looking for a clean, simple way to kill it or force it to return if it is taking too long to execute. I'm using Java. to illustrate: logger.info("sequentially executing all batches..."); for…
carrier
  • 32,209
  • 23
  • 76
  • 99
15
votes
2 answers

Is a generator the callable? Which is the generator?

A generator is simply a function which returns an object on which you can call next, such that for every call it returns some value, until it raises a StopIteration exception, signaling that all values have been generated. Such an object is called…
du369
  • 821
  • 8
  • 22
14
votes
1 answer

What is the implementation of call() in dart?

I somehow found the call() method is on every function. Using this method I could change my if (callback != null) callback() to callback?.call(). So I tried to find the implementation and document of call(), but I couldn't. Is it just built-in…
wurikiji
  • 327
  • 3
  • 12
1
2
3
50 51