Questions tagged [dispatch]

Dynamic dispatch (also known as dynamic binding) is the process of mapping a message to a specific sequence of code (method) at runtime. This is done to support the cases where the appropriate method cannot be determined at compile-time (i.e. statically).

dispatch
Filter by
Sorted by
Tagged with
596 votes
30 answers
139k views

Using a dispatch_once singleton model in Swift

I'm trying to work out an appropriate singleton model for usage in Swift. So far, I've been able to get a non-thread safe model working as: class var sharedInstance: TPScopeManager { get { ...
David Berry's user avatar
  • 41.1k
80 votes
3 answers
101k views

Is there a way to store a function in a list or dictionary so that when the index (or key) is called it fires off the stored function?

For instance, I've tried things like this, which doesn't work: mydict = { 'funcList1': [foo(), bar(), goo()], 'funcList2': [foo(), goo(), bar()]} Is there some kind of structure with this ...
Zack's user avatar
  • 4,295
43 votes
4 answers
71k views

Android - Key Dispatching Timed Out

In my Android application I am getting a very strange crash, when I press a button (Image) on my UI the entire application freezes and after a couple of seconds I getthe dreaded force close dialog ...
Donal Rafferty's user avatar
4 votes
1 answer
919 views

Interpretation vs dynamic dispatch penalty in Python

I watched Brandon Rhodes' talk about Cython - "The Day of the EXE Is Upon Us". Brandon mentions at 09:30 that for a specific short piece of code, skipping interpretation gave 40% speedup, while ...
Jay's user avatar
  • 2,668
6 votes
1 answer
1k views

Wrong specialized generic function gets called in Swift 3 from an indirect call

I have code that follows the general design of: protocol DispatchType {} class DispatchType1: DispatchType {} class DispatchType2: DispatchType {} func doBar<D:DispatchType>(value:D) { ...
Abe Schneider's user avatar
6 votes
3 answers
6k views

How can I implement a dynamic dispatch table in C

First of all, I understand how to implement a dispatch table using function pointers and a string or other lookup, that's not the challenge. What I'm looking for is some way to dynamically add ...
Dave Durbin's user avatar
  • 3,602
1 vote
1 answer
727 views

Dispatch CLI not passing Entities from Luis App

When generating a Dispatch model using the CLI, it doesn't pass the Entities from the Luis app in reference. This drastically affects the accuracy of the dispatch app. For example, for the utterance ...
Alexandre Viegas's user avatar
27 votes
1 answer
23k views

DispatchSourceTimer and Swift 3.0

I can't figure out how to make dispatch timer work repeatedly in Swift 3.0. My code: let queue = DispatchQueue(label: "com.firm.app.timer", attributes: DispatchQueue....
Derreck's user avatar
  • 383
32 votes
2 answers
47k views

How to properly add and use D3 Events?

I'm having trouble understanding using D3 events and dispatch functions. I have a chart example that I've been working on called: "Vertical Bar Charts With Legends." Drawing the charts and the ...
Information Technology's user avatar
36 votes
4 answers
7k views

CLR implementation of virtual method calls to interface members

Out of curiosity: how does the CLR dispatch virtual method calls to interface members to the correct implementation? I know about the VTable that the CLR maintains for each type with method slots for ...
Daniel A.A. Pelsmaeker's user avatar
22 votes
5 answers
15k views

Stop dispatch_after

I use an animation for specify a tip to help the interaction with delay using these: let delay = 1.8 * Double(NSEC_PER_SEC) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) ...
PlugInBoy's user avatar
  • 989
13 votes
4 answers
8k views

Why virtual function call is faster than dynamic_cast?

I wrote a simple example, which estimates average time of calling virtual function, using base class interface and dynamic_cast and call of non-virtual function. Here is it: #include <iostream> ...
D_E's user avatar
  • 1,196
12 votes
5 answers
28k views

Why BackgroundWorker always is busy?

I realized something strange in my background worker in my WPF application. What I'm trying to accomplish right now is to wait until the BW finishes to start another thread. Check the following code:...
Darf Zon's user avatar
  • 6,308
6 votes
4 answers
15k views

dispatch design pattern?

Suppose I have a class hierarchy in Java: interface Item { ... }; class MusicBox implements Item { ... }; class TypeWriter implements Item { ... }; class SoccerBall implements Item { ... }; and I ...
Jason S's user avatar
  • 187k
5 votes
1 answer
12k views

win32com.client.Dispatch works but not win32com.client.gencache.EnsureDispatch

i'm learning win32com for python and I've got a strange problem. I'e trying to export Outlook Contacts in a List of Dictionnary. My code works perfectly with win32com.client.Dispatch("Outlook....
franckgaga's user avatar
3 votes
2 answers
826 views

Fastest implementation of simple, virtual, observer-sort of, pattern in c++?

I'm working my arse off trying to implement an alternative for vtables using enums and a ton of macro magic that's really starting to mess with my brain. I'm starting to think i'm not walking the ...
NicoBerrogorry's user avatar
2 votes
2 answers
2k views

Is the dispatch of a Haskell TypeClass dynamic?

Given the following Haskell code snapshot: class Foo a where bar :: a -> ... quux :: a -> ... ... Where the value of a is determined at runtime - the class dispatches on this value. ...
hawkeye's user avatar
  • 35.2k
68 votes
12 answers
65k views

Get current dispatch queue?

I have a method which should support being called from any queue, and should expect to. It runs some code in a background thread itself, and then uses dispatch_get_main_queue when it returns a value ...
Andrew's user avatar
  • 16k
59 votes
4 answers
9k views

Difference between func() and (*this).func() in C++

I am working on someone else code in C++, and I found a weird call to a certain function func(). Here is an example: if(condition) func(); else (*this).func(); What is the difference between ...
gtatr's user avatar
  • 7,421
30 votes
5 answers
74k views

React Redux dispatch action after another action

I have an async action, which fetch data from REST API: export const list = (top, skip) => dispatch => { dispatch({ type: 'LIST.REQUEST' }); $.get(API_URL, { top: top, skip: skip }) ...
Denis Bednov's user avatar
20 votes
2 answers
11k views

python3: singledispatch in class, how to dispatch self type

Using python3.4. Here I want use singledispatch to dispatch different type in __mul__ method . The code like this : class Vector(object): ## some code not paste @functools.singledispatch ...
jiamo's user avatar
  • 1,456
18 votes
4 answers
7k views

target parameter in DispatchQueue

In Swift 3, the creation of a DispatchQueue instance: DispatchQueue(label: String, qos: DispatchQoS, attributes: DispatchQueue.Attributes, ...
pzs7602's user avatar
  • 1,253
16 votes
1 answer
15k views

how to dynamically call instance methods in typescript?

I have an object and I want to dynamically call a method on it. Having typechecking would be nice but that maybe impossible. But I can't even get it to compile at all currently: const key: string ...
dcsan's user avatar
  • 11.8k
10 votes
4 answers
12k views

Is it possible to dispatch events on regular objects (not DOM ones)? [duplicate]

I just found out that FileReader dispatches events just as if it was a DOM element. Is it? I wonder if it's possible to create an object similar to FileReader, which doesn't have a representation in ...
jayarjo's user avatar
  • 16.5k
10 votes
2 answers
1k views

Is S4 method dispatch slow?

My S4 class has a method that is called many times. I noticed that the execution time is much slower than it would be if a similar function was called independently. So I added a slot with type "...
Soldalma's user avatar
  • 4,728
8 votes
2 answers
9k views

How to convert dispatch_data_t to NSData?

Is this the right way? // convert const void *buffer = NULL; size_t size = 0; dispatch_data_t new_data_file = dispatch_data_create_map(data, &buffer, &size); if(new_data_file){ /* to avoid ...
hfossli's user avatar
  • 22.8k
8 votes
1 answer
7k views

What does Znwm and ZdlPv mean in assembly?

I'm new to assembly and I'm trying to figure out how C++ handles dynamic dispatch in assembly. When looking through assembly code, I saw that there were 2 unusual calls: call _Znwm call _ZdlPv ...
user2999870's user avatar
5 votes
2 answers
4k views

Is dispatch_sync(dispatch_get_global_queue(xxx), task) sync or async

As Apple's document says, dispatch_get_global_queue() is a concurrent queue, and dispatch_sync is something meaning serial.Then the tasks are processed async or sync?
keywind's user avatar
  • 1,165
4 votes
3 answers
3k views

Dispatch action on the callback of socket.on()

So basically I got this socket, that is working correctly sending me 'new order' message. I'm using redux, and i want to dispatch an action, than a reducer would get it and my store would be updated. ...
Amanda Siqueira's user avatar
4 votes
4 answers
9k views

dispatch_after looped / repeated

I am trying to create a loop like this: while (TRUE){ dispatch_after(...{ <some action> }); } After a viewDidLoad. The idea is to repeat the dispatch_after repeatedly. The ...
Roel Van de Paar's user avatar
3 votes
1 answer
735 views

Understanding Dean Edwards' addevent JavaScript

I need help understanding this piece of code. What is the point of handler.guid? Why is there a need for a hash table? What is the point of: if ( element["on" + type]) { handlers[0] = ...
steve's user avatar
  • 1,921
1 vote
1 answer
2k views

How to dispatch tcp request to backends with first byte of content in openresty lua

I have started a openresty with one tcp server and two backends. The tcp server dispatch the request to backends according to the content from tcp stream. Following is an example of openresty ...
Ch Ou's user avatar
  • 11
0 votes
1 answer
929 views

How to set up DispatchGroup in asynchronous iteration?

I´m trying to set up an iteration for downloading images. The whole process works, but taking a look in the console´s output, something seems to be wrong. func download() { let logos = [Logos]() ...
Josch Hazard's user avatar
-1 votes
3 answers
2k views

Java Generic / Type Dispatch Question

Consider the following program: import java.util.List; import java.util.ArrayList; public class TypeTest { public static class TypeTestA extends TypeTest { } public static class ...
tracer's user avatar
  • 3,335
38 votes
2 answers
31k views

What is dispatch used for in django?

I have been trying to wrap my head around the dispatch method, particularly in Django. However, I cannot seem to figure out exactly what it does. I tried to gain an understanding from the Django docs ...
Taylor Hardie's user avatar
26 votes
3 answers
66k views

Typescript: How to type the Dispatch in Redux

For example I want to remove the dispatch: any here: export const fetchAllAssets = () => (dispatch: any) => { dispatch(actionGetAllAssets); return fetchAll([getPrices(), getAvailableSupply()...
Leon Gaban's user avatar
  • 38.3k
15 votes
4 answers
3k views

How can I write self-modifying code that runs efficiently on modern x64 processors?

I'm trying to speed up a variable-bitwidth integer compression scheme and I'm interested in generating and executing assembly code on-the-fly. Currently a lot of time is spent on mispredicted ...
Nathan Kurz's user avatar
  • 1,669
11 votes
1 answer
32k views

What does "dispatch()" mean/do, and why is it used when we have .then() and .catch()

I am new to ES6 and advanced javascript. I have seen examples of code using the axios http client like this: axios.xxx(...).then((res) => dispatch(success(res)) , (err)=> dispatch(error(err))) ...
yen's user avatar
  • 1,932
10 votes
1 answer
9k views

How to test react useContext useReducer dispatch in component

hope someone can point me the right direction with this. Basically I've created a react app which makes use of hooks, specifically useContext, useEffect and useReducer. My problem is that I can't ...
Noelt's user avatar
  • 131
9 votes
2 answers
6k views

How to implement Flask Application Dispatching by Path with WSGI?

I would like to use a single domain as a Staging Environment for multiple flask applications that will eventually run on their own domains. Something like: example_staging.com/app1 example_staging....
detachedhead's user avatar
9 votes
3 answers
3k views

How do we dispatch Google Analytics events when iOS app goes to the background?

My iOS app has links to Apple's App Store in it and I am trying to track those as events. The problem is that we can't get my app to properly dispatch the GA events before it goes into the background....
Will's user avatar
  • 111
9 votes
4 answers
2k views

Dynamic dispatch to derived class in C#

I'm trying to do the following: public abstract BaseClass { public virtual void ReceiveEvent(Event evt) { ProcessEvent(evt as dynamic); } private void ProcessEvent(object evt) ...
Jamona Mican's user avatar
  • 1,634
9 votes
2 answers
1k views

Use invokedynamic to implement multiple dispatch

I wondered if Java7's new invokedynamic bytecode instruction could be used to implement multiple dispatch for the Java language. Would the new API under java.lang.invoke be helpful to perform such a ...
Matt's user avatar
  • 868
8 votes
3 answers
19k views

Swift DispatchGroup notify before task finish

I'm using DispatchGroup to perform a task, but group.notify is being called before the task is completed. My code: let group = DispatchGroup() let queueImage = DispatchQueue(label: "com.image") let ...
Victor's user avatar
  • 109
6 votes
4 answers
223 views

Signature can't be resolved when it's aliased to a constant

As a follow up to this question about using different APIs in a single program, Liz Mattijsen suggested to use constants. Now here's a different use case: let's try to create a multi that ...
jjmerelo's user avatar
  • 23k
5 votes
2 answers
6k views

Is there a way to create and dispatch/trigger custom event with react-navigation?

With DOM, you can easily create a trigger custom event with Javascript like so: var event = new Event('build'); // Listen for the event. elem.addEventListener('build', function (e) { /* ... */ }, ...
Monero Jeanniton's user avatar
5 votes
5 answers
937 views

How do I dispatch to a method based on a parameter's runtime type in C# < 4?

I have an object o which guaranteed at runtime to be one of three types A, B, or C, all of which implement a common interface I. I can control I, but not A, B, or C. (Thus I could use an empty marker ...
Evan Barkley's user avatar
5 votes
3 answers
4k views

AS3 - Event listener that only fires once

I'm looking for a way to add an EventListener which will automatically removes itself after the first time it fires, but I can't figure a way of doing this the way I want to. I found this function (...
Zed-K's user avatar
  • 991
5 votes
2 answers
4k views

C++ function dispatch with template parameters

I'm in the process of refactoring a large class -- let's call it Big -- that has a huge amount of copy-paste code. Much of this copy-paste code exists in switch cases where only the types involved end ...
Spire's user avatar
  • 685
5 votes
3 answers
498 views

Method will not match with nested type restrictions

I have this simple method which calculates the weighted average of a collection of vectors function meanw{T <: Number}(x::AbstractArray{AbstractVector{T}, 1}, w::AbstractVector{T}) x̄ = sum(x .* ...
Godisemo's user avatar
  • 1,813