Call a function after previous function is complete
Specify an anonymous callback, and make function1 accept it:
$('a.button').click(function(){
if (condition == 'true'){
function1(someVariable, function() {
function2(someOtherVariable);
});
}
else {
doThis(someVariable);
}
});
function function1(param, callback) {
...do stuff
callback();
}
How to call functions after previous function is completed in python?
Use a global variable. Set it in function1, and check it in function2.
function1_success = False
def function1():
global function1_success
# do stuff ...
if success:
function1_success = True
def function2():
global function1_success
if function1_success:
# do stuff ...
Javascript call function after another function executes
Well since it is an asynchronous task, you need to add logic to tell the next code when to run. Classic way is to use a a callback method:
function make_base(img, callback) {
base_image = new Image();
base_image.src = img;
base_image.onload = function(){
context.drawImage(base_image, 0, 0);
callback()
}
}
function text(text) {
context.fillText(text, 50, 50)
}
function render() {
make_base(xxx, function () {
text(xxx)
})
}
or move into modern patterns is to use a promise
function make_base(img) {
return new Promise(function(resolve, reject) {
base_image = new Image();
base_image.src = img;
base_image.onload = function(){
context.drawImage(base_image, 0, 0);
resolve()
}
}
function text(text) {
context.fillText(text, 50, 50)
}
function render() {
make_base(xxx).then(function () {
text(xxx)
})
}
How to call functions after previous function is completed in Flutter?
Transform your popUpForGroup to async function like this.
Future<void> popUpForGroup({...}) {...}
After that and inside your onPressed Function you can write this:
onPressed: () async => {
await popUpForGroup("Add Group", null, context),
print("pop up closed"),
refreshPage(),
},
Execute javascript function after previous one finishes
There's many different approaches to this but I would suggest using a Promise like this:
document.getElementById('btnSend').addEventListener('click', e => { e.preventDefault(); var result = validateInputs(email, subject, message); if(result){ showElement(document.getElementById('formGroupSpinner'), 2000).then(()=>{ return showElement(document.getElementById('formGroupSuccessImg'), 2000); }).then(()=>{ resetForm(); }); }});
//expects an html element and a number representing miliseconds. Shows the html element for that amount of time.function showElement(element, mSeconds) { return new Promise((resolve, reject) => { element.classList.remove('d-none'); element.classList.add('d-block'); setTimeout( () => { element.classList.remove('d-block'); element.classList.add('d-none'); resolve(); }, mSeconds); });}
Related Topics
JavaScript - How to Show Escape Characters in a String
Regarding Promises/A+ Specification, Differencebetween the Terms "Thenable" and "Promise"
Pretty Printing Xml with JavaScript
Why Is Requestanimationframe Better Than Setinterval or Settimeout
Immediate Function Invocation Syntax
How to Async Await in React Render Function
Javascript: Class.Method VS. Class.Prototype.Method
How Can Jquery Deferred Be Used
How to Convert an Integer to Binary in JavaScript
How to Screenshot Website in JavaScript Client-Side/How Google Did It? (No Need to Access Hdd)
Why Should I Use a Semicolon After Every Function in JavaScript
How to Filter (Key, Value) with Ng-Repeat in Angularjs
Uncaught Typeerror: Illegal Invocation in JavaScript
Fetch: Reject Promise and Catch the Error If Status Is Not Ok