cocos2d(x), execute something on next frame? - menu

For example, I'm adding a menu and want to set it's priority.
setHandlerPriority checks if the menu is associated with a touch handler and it fails because addition is scheduled on next loop(pushed onto a queue).
How can I add a menu(as a child) and set its priority at the same time?
Or how can I call the 'setHandlerPriority' on next loop?
Does 'runAction' with 'CCCallFunc' execute the function on next frame?
Thank you

you can create a sequence of actions.
those actions can be a CCDelayTime or CCCallFunc, then they can be called with the order you want it to be. just use any CCNode to run that action.

Related

Why Until loop ends earlier?

I am performing an until loop in logic app. In this loop I'm using a delay function to do the next loop. But if we manage the delay unit to hour, the loop will end in the second time. That means the loop will only executed twice!(Escalation variable is 72 and LoopCounter increments from 0) I want to know if it is a bug from logic app or I did some wrong settings.
Please see the settings as below.
This issue seems to be with 'Until Loop' timeout. To resolve this you can try the following ways:
It looks like this is due to a bug in the way we evaluate the timeout limit value in the until scope.
Remove the triggerBody{} from the limit.timeout property – i.e. make a it a static value
If you really need to make the timeout computation dependent on the payload of the trigger request, you may want to add the “triggerBody()” into the “expression” property of the “until” (this is because we parse the expression when loading dependencies before the action is run)
For example:
You can refer to Configure Logic App 'Until Loop' timeout dynamically, Iteration in Logic Apps terminates prematurely, Until Loop Dynamic Count Limit and Add the Delay-until action

Control close event pyglet

I have a program that has multiple windows in pyglet, and I want to make one window unclosable, rather to set its visibility to false. Is there a way I can access the event handle for close, to make it instead of closing the window, possibly return a bool or a string like "should close."?
Found the answer to my own question, first define a custom event loop with window_event_loop = pyglet.app.EventLoop(), then create a handler for .event for the event loop
#window_event_loop.event
def on_window_close(window):
# Extra code here
return pyglet.event.EVENT_HANDLED

Terminating each() block in Protractor

I was automating the an application (using Protractor) and I have come across situation where I wanted to select the an option from the type ahead using the DOWN arrow button from the Keyboard. Here is how I am approaching to this action.
After typing part into the text field I am getting the reference of each option that appear in the type ahead.
Now, I am using .each() method of protractor to iterate through each of the option to look for the required option.
I'm making the script to hit DOWN arrow button to iterate through each option in the type ahead.
Suppose there are 10 options displayed in the type ahead and the option that I need to select is at 5th position. Now when I reach the 5th position I am selecting the option but each() function still continues.
I want the loop to terminate when required option is selected. Something like BREAK statement in FOR loops.
BTW I have tried the above scenario with FOR loop but unable to use BREAK statement within then() handler.
Please let me know how to cope up with this situation.
You could throw an exception to terminate the loop. Put the loop inside try and use catch to wrangle your results. You can also just use a boolean variable to indicate that you have found a match and ignore everything after that point. I would just use a for loop though.
Edit:
You could add a variable to hold an action before the allBenchmarks.each
var action
Then inside the test
if(dataValue == optionToSelect){
action = function() {benchmark.click(); ...}
}
After the loop exits call the action
if (action) action()

Tkinter traffic-jamming

I have an expensive function that is called via a Tkinter callback:
def func: # called whenever there is a mouse press in the screen.
print("Busy? " + str(X.busy)) # X.busy is my own varaible and is initialized False.
X.busy = True
do_calculations() # do_calculations contains several tk.Canvas().update() calls
X.busy = False
When I click too quickly, the func()'s appear to pile up because the print gives "Busy? True", indicating that the function hasen't finished yet and we are starting it on another thread.
However, print(threading.current_thread()) always gives <_MainThread(MainThread, started 123...)>, the 123... is always the same each print for a given program run. How can the same thread be multiple threads?
It looks to me like you're running into recursive message processing. In particular, tk.Canvas().update() will process any pending messages, including extra button clicks. Further, it will do this on the same thread (at least on Windows).
So your thread ID is constant, but your stack trace will have multiple nested calls to func.

.NET Task: How can I create a collection of tasks that can all be executed synchronously or asynchronously?

In my application, I add a bunch of operations to a List(Of Task) like below:
Dim Tasks As New List(Of Task)
Tasks.Add(Task.Factory.StartNew(Sub()
System.Threading.Thread.Sleep(3000)
End Sub))
Tasks.Add(Task.Factory.StartNew(Sub()
System.Threading.Thread.Sleep(3000)
End Sub))
Task.WaitAll(Tasks.ToArray())
When I call Task.WaitAll(Tasks.ToArray()), it executes all tasks simultaneously as expected. However, debugging/stepping through threaded methods is a bit difficult to do, so I'd like to be able to execute all of these synchronously (I'd create an AppSetting in my config file that I could use to determine whether or not to run the tasks synchronoulsy or asynchronously). However, calling .RunSynchronously() on a Task that has been created using .StartNew() throws an exception.
How should I build this list of tasks so that I can toggle between synchronous and asynchronous execution?
Edit: Conceptually, here is what I would like to do:
If ConfigurationManager.AppSettings("ExecuteAsynchronously") = "1" Then
Task.WaitAll(Tasks.ToArray())
Else
Task.WaitAllAsynchronously(Tasks.ToArray())
End If
I know that .WaitAllAsynchronously() doesn't exist, but you can still see the end result of what I am trying to achieve. If I have to create an extension method called .WaitAllAsynchronously() that iterates through each task an executes it synchronously then that's what I will do.
Since .StartNew() doesn't support sychronous execution, I need to build my list of tasks without actually starting them, but in a way that supports both synchronous and asynchronous execution.
You can use the Parallel.Invoke and set it to use a single thread.
Dim po AS new ParallelOptions()
po.MaxDegreeOfParallelism = 1
Parallel.Invoke(po,
Sub()
System.Threading.Thread.Sleep(3000)
End Sub,
Sub()
System.Threading.Thread.Sleep(3000)
End Sub
)
I figured out a way to do what I want using Tasks. I was going to just delete my question, but I felt others may benefit from this, so here is what I did:
Dim ExecuteSynchonously As Boolean = True
Dim Tasks As New List(Of Task)
Tasks.Add(New Task(Sub()
System.Threading.Thread.Sleep(3000)
End Sub))
Tasks.Add(New Task(Sub()
System.Threading.Thread.Sleep(3000)
End Sub))
'will create helper extension methods for these
If ExecuteSynchonously Then
Tasks.ForEach(Sub(t)
t.RunSynchronously()
End Sub)
Else
Tasks.ForEach(Sub(t)
t.Start()
End Sub)
Task.WaitAll(Tasks.ToArray)
End If
First, I build the collection by adding non-started tasks to the collection (as opposed to .StartNew()). You can follow the rest. I will ultimately create helper methods for these, but this at least shows the core code I used.
If anyone sees a more efficient way to do this, please let me know.

Resources