Function after Android Asynctask.execute() - android-asynctask

Just out of curiosity, if I have a function right after android's Asyntask.execute(), can this function be executed before Asynctask's execution is completed?

Related

Kotlin Coroutines run all operation on the same Thread

I am using the V8 JavaScript engine in my app. It enforces that all operations executed on the same thread that it was initialised on.
I have introduces a CoroutineContext out of a HandlerThread using asCoroutineDispatcher() extension
Using that context, for every function I do:
suspend fun executeRandomCode() = withContext(jsContext) {
// run desired V8 code
}
So my question is, if i run the following code:
ioScope.launch {
executeRandomCode()
executeRandomCode2()
executeRandomCode3()
}
Is there any overhead of doing multiple function calls where each function does withContext(jsContext)?
Is there a better way to enforce single thread using coroutines?

RSVP.js promise running before .then() is called

I presume this is a basic mistake, but as my searches made no effect, let's do it here anyway :)
I have a function returning a promise, but it runs so fast (because code is almost empty) that when .then() is called, it is too late and no event is called.
The reason why it happens is because that's a dummy code (for testing), so, the Promise concept is applied because of a situation where an actual async request is done.
So, is there a way to call the resolve/reject functions even after the function was processed? Or I would have to use lazy promises?
Update: I tried RSVP.defer() but didn't like its approach as it's not intuitive enough (requires some workaround to set .then() and .catch(), etc.
I have a function returning a promise, but it runs so fast (because code is almost empty) that when .then() is called, it is too late and no event is called.
That does not matter even one bit. Well behaved promises (like native promises, and virtually every library except old jQuery) are built with a guarantee that no matter when you attach the then handler - it will call the handler (and it will always do so asynchronously). A promise is just a value + time.
RSVP passes a suite of over 1000 tests to ensure this is always the case.
var p = Promise.resolve(); // create empty, already resolved promise
setTimeout(function(){
p.then(function(){
// will always be called, eventually.
});
}, 1000000 + Math.random() * 10000000);

How does another program/process interrupt the execution of my program?

Lets say I have written a very simple program in an operating system which supports UI. My program looks like below:-
#include <os_specific_ui.h>
int main()
{
// Create a button using os specific API
object my_button = add_button("I am a button");
// Register for a mouse down call back on that button
mouse_down_handler = register_mouse_down_cb(my_button, func_to_be_called_on_mouse_down);
// do something...
// have a lot of functions which keep calling each other for a long period of time
}
void func_to_be_called_on_mouse_down(void)
{
print("my_button got clicked");
}
The program is clearly a single threaded program. When I run it, it keeps on doing something. In the mean time if there is a mouse down event, then callback registered for it will get hit and start executing.
I want to know how can another process (which handles mouse movements) can call a function in my process? And what happens to the state of my process when such a callback is hit. I mean my program was doing something when callback was hit. So it just stops doing that and starts executing callback or what? And what after the callback function finishes executing? Does my program go back to do whatever it was doing before callback was hit?
Pretty much all GUI programs run some form of event/main loop. That is, as the last part in main() it enters a loop, which reads events from the OS, and dispatches those events to your callback handlers and performs other tasks to realize the GUI.
i.e. the code you have in // have a lot of functions which keep calling each other just isn't possible unless you do that in a separate thread. Your own execution flow isn't stopped and taken over by some other process.
A GUI program is more or less done like this:
#include <os_specific_ui.h>
void func_to_be_called_on_mouse_down(void)
{
print("my_button got clicked");
}
int main()
{
// Create a button using os specific API
object my_button = add_button("I am a button");
// Register for a mouse down call back on that button
mouse_down_handler = register_mouse_down_cb(my_button, func_to_be_called_on_mouse_down);
for (;;) {
Event e
read_event_from_OS(&e);
handle_event(&e);
}
}
Where read_event_from_OS() fetches mouse/keyboard/redraw/etc. events from the operating system, and handle_event() figures out what to do with that event, such as redraw a window, or call one of the callback functions that your program has registered.
If the OS you're working on does things differently, you'll have to tell us more about it

How do you fire forge.ajax periodically in Trigger.io app?

Does anyone have an example of how to fire forge.ajax periodically in a Trigger.io app? It seems to fire once, then die silently. Is Trigger.io removing the setTimeout or stopping it? I'm using this technique adapted from Paul Irish.
// Wrap this function in a closure so we don't pollute the namespace
(function worker() {
forge.request.ajax({
url: 'ajax/test.html',
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 5000);
}
});
})();
Could it be a scope issue perhaps?
Thanks for any advice.
While forge.request.ajax is similiar to jQuery.ajax it is not the same, and it has no complete callback.
You probably want to put your setTimeout in both the success and error callbacks.

How to call a function after the update progress is completed in an update panel?

I have a button in the update panel. Another function say function1 is executed in the click event of this button. I want to call a javascript function once the function1 completes execution. How will I know when the function1 has completed its execution?
Assuming function1 runs onthe server, and function2 on the client,
handle the endRequest event of the Sys.WebForms.PageRequestManager MSAjax class.

Resources