Calling same function from other two function - iphone

I am want to know if there is any way to call a same function from other two functions.
Like, say ..fucntion1 calls the MainFunction and then after function1 has done using the main function, function2 should call the MainFunction.
I have learned that this can be achieved using NSOperation queues ? But that is for asynchronous execution, I do not want that.
Is there any other way to achieve this ?
Any help will be truly appreciated, Thank you for your time. :)

You can use dispatch_sync(). It's part of the GCD API.

Use below method, it may helps you
[self performSelectorInBackground:(SEL) withObject:(id)]

Thank you all for your help ..! I ended up using delegates to solve this issue, I inserted a delegate callback, which gives me a callback after the first function completes using the MainFucntion and after getting the callback i called that MainFucntion using the secondMethod.

Related

Anylogic Custom Flow Block how to call a function

I am wondering that how could we call function in custom flow block in anylogic. Should we need to use some parameters? I used MYAGVWorkstation as Custom flow block as https://anylogic.help/library-reference-guides/process-modeling-library/custom-block.html. Now I want to call function at seizeAGV-SizeTransport. I tried but its giving error.
Looking forward to some help and thanks in advance.
Reference

how to identify a callback or link a callback to a previous function?

just started learning and bumped into this callback thing, not sure I fully follows this example below, callback is an argument for function inputName, but how is it being linked to the previous function sayHello? I think I missed the logic flow here>, is it possible there are two callbacks? how to decide which one to refer to then, many thanks.
enter image description here

Pre/Post-Handler Hook for Micronaut

I was wondering if there is some way to provide two methods to Micronaut which are guaranteed to run before and after a request was passed to the handler.
In my case, this would be to initialize some thread-local data.
I know this would also be possible to put in the handler itself but putting the same lines of code in every handler isn't really the greatest solution.
Use a filter - see the docs at https://docs.micronaut.io/latest/guide/#filters

What, if any, guarantees are there for when `nalu_process` will be called?

In particular, can a call to x264_encoder_encode return before every nalu_process callback associated to it has returned? Someone in #x264 suggested it's settings-dependent; I'm talking here about the "zerolatency" preset.
If the answer to the above question is yes, then how common is it, empirically?
According to BugMaster on #x264 on Freenode, nalu_process is always called when inside x264_encoder_encode. I'll take his word for it.

How to synchronise callback function when in a loop

I am pretty new to iPhone development. i need some help on how to synchronize a callback method and a for loop.
For example:
I have a for loop say 1 to 3.
Within this loop, first i send message to a receiver. The result from the receiver is obtained in a callback function. With this result i need to perform some parsing. Now how can i continue with the loop??
BR,
Suppi
Edited with Code:
-(void)requestData{
for (int i=1; i<3; i++) {
completeMessage = [self generateMessage:message];
[self sendMessageToReceiver:completeMessage];
//now it goes to the callback function to read message from receiver. How do i return to this point?? to continue the loop.
[self dosomething:result];
}
}
I don't know much about iPhone development but based on my asynchronous function calling experience you might have to reconsider your approach - assuming this is an asynchronous function call.
When you go through the loop the first time, your code is going to call all the asynchronous functions and move on. It is not going to wait. If you want it to wait for each function call then you either shouldn't use asynchronous functions or use a thread.wait or thread.sleep function in the loop. You could also use some kind of thread synchronization and signalling in the loop. For example, you could make the asynchronous call and then your thread waits until it gets a signal from your callback to continue.
You may want to take your custom end processing out of the loop and do it after all your callbacks are done. You could put state in a common location for each of your callbacks and use it after the callbacks are done.
Of course, you would need to wait until all the callbacks are done before you can continue.
Hope this helps.
Launch the message in a separate thread:
[receiver performSelectorInBackground:#selector(doSomething)];
use performSelectorInBackground:withObject: if you wish to pass a parameter.
Convert your "for" loop into the equivalent goto statements. Then break the goto basic blocks into methods and method calls without goto's. Then break the method containing the wait into 2 methods and use an asynchronous call and callback in between them. You may have to save some of the local and for loop's implicit state in instance variables.
Goto's are not always bad. They are just implicit in more readable structured and/or OOP messaging constructs. Sometimes the compiler can't do the conversion for you, so you need to know enough about raw program control sequencing to do it yourself.