delaying actions between keypress in jQuery

You can use jQuery’s data abilities to do this, something like this: $(‘#mySearch’).keyup(function() { clearTimeout($.data(this, ‘timer’)); var wait = setTimeout(search, 500); $(this).data(‘timer’, wait); }); function search() { $.post(“stuff.php”, {nStr: “” + $(‘#mySearch’).val() + “”}, function(data){ if(data.length > 0) { $(‘#suggestions’).show(); $(‘#autoSuggestionsList’).html(data); }else{ $(‘#suggestions’).hide(); } }); } The main advantage here is no global variables all … 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

Idiomatic jQuery delayed event (only after a short pause in typing)? (aka timewatch/typewatch/keywatch)

I frequently use the following approach, a simple function to execute a callback, after the user has stopped typing for a specified amount of time:: $(selector).keyup(function () { typewatch(function () { // executed only 500 ms after the last keyup event. }, 500); }); Implementation: var typewatch = (function(){ var timer = 0; return function(callback, … Read more

Xcode Objective-C | iOS: delay function / NSTimer help?

sleep doesn’t work because the display can only be updated after your main thread returns to the system. NSTimer is the way to go. To do this, you need to implement methods which will be called by the timer to change the buttons. An example: – (void)button_circleBusy:(id)sender { firstButton.enabled = NO; // 60 milliseconds is … Read more

Delay Actions in Swift

dispatch_after() is the standard way of delaying actions. indicator.startAnimating() let delay = 4.5 * Double(NSEC_PER_SEC) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) dispatch_after(time, dispatch_get_main_queue()) { indicator.stopAnimating() } See: dispatch_after – GCD in swift? Update for Swift 3.0 indicator.startAnimating() let delay = Int(4.5 * Double(1000)) DispatchQueue.main.after(when: .now() + .milliseconds(delay)) { indicator.stopAnimating() } However, in the spirit of Swift … 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

Flutter/Dart – Open a view after a delay

You can do it in 2 ways: Using Timer class. import ‘dart:async’; // Go to Page2 after 5s. Timer(Duration(seconds: 5), () { Navigator.push(context, MaterialPageRoute(builder: (_) => Screen2())); }); Using Future.delayed class: // Go to Page2 after 5s. Future.delayed(Duration(seconds: 5), () { Navigator.push(context, MaterialPageRoute(builder: (_) => Screen2())); }); The benefit of using Timer over Future is … Read more

How windows handle the clipboard interface with Xming?

Your observation that the delay is proportional to the number of characters pasted should be expected, since each of those characters must be fed through the SSH terminal, a serial pipeline. Additionally, rendering those characters on your end takes some effort from Windows. I suspect that the reason that you see less delay with your … Read more