jQuery: append() object, remove() it with delay()

Using setTimeout() directly (which .delay() uses internally) is simpler here, since .remove() isn’t a queued function, overall it should look like this: $(‘body’).append(“<div class=”message success”>Upload successful!</div>”); setTimeout(function() { $(‘.message’).remove(); }, 2000); You can give it a try here. .delay() is for the animation (or whatever named) queue, to use it you’d have to do something … Read more

How to put a delay on AngularJS instant search?

UPDATE Now it’s easier than ever (Angular 1.3), just add a debounce option on the model. <input type=”text” ng-model=”searchStr” ng-model-options=”{debounce: 1000}”> Updated plunker: http://plnkr.co/edit/4V13gK Documentation on ngModelOptions: https://docs.angularjs.org/api/ng/directive/ngModelOptions Old method: Here’s another method with no dependencies beyond angular itself. You need set a timeout and compare your current string with the past version, if both … Read more

Delaying function in swift [duplicate]

You can use GCD (in the example with a 10 second delay): Swift 2 let triggerTime = (Int64(NSEC_PER_SEC) * 10) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, triggerTime), dispatch_get_main_queue(), { () -> Void in self.functionToCall() }) Swift 3 and Swift 4 DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: { self.functionToCall() }) Swift 5 or Later DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { //call any function … Read more

Add a delay after executing each iteration with forEach loop

What you want to achieve is totally possible with Array#forEach — although in a different way you might think of it. You can not do a thing like this: var array = [‘some’, ‘array’, ‘containing’, ‘words’]; array.forEach(function (el) { console.log(el); wait(1000); // wait 1000 milliseconds }); console.log(‘Loop finished.’); … and get the output: some array … Read more

implement time delay in c

In standard C (C99), you can use time() to do this, something like: #include <time.h> : void waitFor (unsigned int secs) { unsigned int retTime = time(0) + secs; // Get finishing time. while (time(0) < retTime); // Loop until it arrives. } By the way, this assumes time() returns a 1-second resolution value. I … Read more