SpriteKit: run code or block when action removed? - animation

The run function for SKNode lets you run a block when the action completes, but what if the action is cancelled/removed via removeAllActions?
Cancelling an action doesn't invoke the completion block from the run function.
Is there a callback or way to run code when the action is cancelled/removed?

Yes, if you remove an action before it has completed, the completion block will not run. Per Docs:
The run(:completion:) method is identical to the run(:) method, but after the action completes, your block is called. This callback is only called if the action runs to completion. If the action is removed before it completes, the completion handler is never called.

A work around could be:
class YourSpriteNode: SKNode {
func doSometingAtCompletionAction() {
//all your stuff
}
override removeAllActions() {
super.removeAllActions()
doSometingAtCompletionAction()
}
}

Related

How Subscribe works

I am learning the rxjs and playing with observable and subscribe. I have the following method in component.ts file which returns true/false from API
this.http.get(apiUrl+"/actionName")
.subscribe(result=>
{
if(result){
//step1
//1.show success message
//2.call the other method
//3.and after returned from here
}else{// not true
//1. show error message
//2. returned from here
}
});
});
//step2
// call another function
}
Whenever I subscribe to an observable it immediately jumps to the next line i.e. step 2 and another method gets called first. Which I don't want to do.
I want to run step1 first until it gets finished completely only then it should go to step2.
Thank you in advance.
You don't say so in your question, but I suspect your
//2.call the other method
line contains a nested subscription or a promise. If that's the case, of course your synchronous code will be run before your asynchronous code is run. JavaScript is a single-threaded environment, so you can never wait for other code to run.
Instead, use RxJS various operators to manage the order of your code for you. How you want to do that depends on what you're doing, though sadly call the other method isn't descriptive enough.
Assuming theOtherMethod and anotherFunction are actually strangely named observables, then you might do something like this:
this.http.get(apiUrl+"/actionName").pipe(
switchMap(result => {
if(result){
return theOtherMethod;
}
return of("There's no result")
}),
switchMap(otherMethodResult => anotherFunction)
).subscribe(anotherFunctionResult => {
/* Ignore result?*/
});

Laravel 8 queue batch callback funktions crash on calling $this Object

I want to do some specific tasks in the callback functions like logging via print_r() method or calling object methods via $this object. But all that fails so i wonder what the scope of these callback functions is. Its somewhat mysterious. I didnt find anything regarding this via google, i think this feature is too new and hasnt been explored widely.
What works though is calling static class methods like
self::doSomething();
Here is the basic structure from the official doc, added my methods in then and finally callback branches:
$batch = Bus::batch(
$batchedObjects
)->then(function (Batch $batch) {
// All jobs completed successfully...
// this method call does not work
$this->doSomething();
})->catch(function (Batch $batch, Throwable $e) {
// First batch job failure detected...
})->finally(function (Batch $batch) {
// The batch has finished executing...
// this method call works
self::doSomething();
})->onQueue('myQueue')->dispatch();

How To Get Data From A Custom Event In Magento

I have an observer module that I have written for Magento. It simply monitors an event called mgd_order_prep which is triggered by a custom dispatcher like this:
Mage::dispatchEvent("mgd_order_prep", array('orderdata' => $order));
$order is simply a magento sales/order object.
My event fires and my function in the proper class executes:
function updateOrderPrepPDF($observer)
{
Mage::log("Update Order Prep",null,'orderprep.log');
Mage::log($observer->getOrderdata(),null,'orderprep.log');
}
I see what I should after the first log event, but I dont see ANYTHING for when I try to output the order data (it outputs blank - or null).
How do I get the data I pass in at the dispatch event out at the execution point?
You can directly get Data using getData() method :
function updateOrderPrepPDF($observer)
{
Mage::log(print_r($observer->getData(),true),null,'orderprep.log');
}
Check this log inside var/log directory.
Try this code and let me know if you still have any query.

how to invoke a method from an Entry Widget in Ruby Tk

I'm looking for an option or a way to bind an event, which invokes a method from an Entry-Widget.
Like the command option for button-widgets: command { method } or
like binding an event for combobox-widgets:
$combobox.bind("<ComboboxSelected>") { method }
Now I'm looking for something similar for Entry-Widgets. I want to invoke a method every time an entry (value) has been edited. That's my initial situation:
$foo = TkVariable.new
$entry = Tk::Tile::Entry.new(parent) {
validate 'key'; validatecommand method; textvariable $foo
}
validatecommand works only at the first time.
If you change the content of the widget during the validation callback and still want to have a validation callback applied in the future, you must re-apply the validation callback. This is documented (for the core Tk version of this, see the end of the validation section of the entry docs) but pretty obscure, to be fair.
Use Tk::after.idle to schedule some code to reapply the validation callback inside the validation callback.

How to get a Boolean return value from jQuery trigger method?

I have a custom event that I want to fire using jQuery's trigger method:
$(wizard).trigger('validatingStepValues');
Then in the wizard's current step code, I subscribe to this event as follow:
$(wizard).bind('validatingStepValues', function (){
// Validating step's form data here; returning false on invalid state.
});
Then in my wizard, again I want to be able to stop user from going to the next step, if a false value is returned from validation process? I'd like to have something like:
$(wizard).trigger('validatingStepValues', validReturnCallback, invalidReturnCallback)
Have you considered using something like:
function wizardValidator(successCallback, failureCallback) {
return function() {
// Validating step's form data here;
if (wasValid && successCallback) {
successCallback();
}
else if (! wasValid && failureCallback) {
failureCallback();
}
return wasValid;
};
}
$(wizard).bind('validatingStepValues', wizardValidator(validReturnCallback, invalidReturnCallback));
This requires that you know the callbacks that you want to use at the time you bind the event listener. If you want to be able to use different callback functions at different times, you could define additional event types, like:
$(wizard).bind('validatingStep2Values', wizardValidator(validStep2ReturnCallback, invalidStep2ReturnCallback));
$(wizard).bind('validatingStep3Values', wizardValidator(validStep3ReturnCallback, invalidStep3ReturnCallback));
Alternately, events that you create by calling trigger() propagate up the DOM hierarchy. Returning false an event handler cancels this propagation. So you could bind your desired success callback function as an event listener on your wizard's parent node. That won't do anything to allow your failure callback to be executed, however.

Resources