Questions tagged [timeout]

Code that handles a condition (normally an error condition) triggered when an event fails to occur within a predefined time limit. For discussing inefficient code that takes an unreasonable amount of time to finish, use the [time-limit-exceeded] tag instead.

Filter by
Sorted by
Tagged with
1 vote
1 answer
81 views

Request-response model over sockets/websockets

This is a request-response model over sockets/websockets (like HTTP) where you technically match request id to response id and return the response. In addition to that, there is timeout in case that ...
nop's user avatar
  • 699
4 votes
1 answer
84 views

Launching two goroutines in parallel and returning result of the first finished

Real case: I need to retrieve data from a web service (main process), but in case that web service is taking too long, I retrieve the data from the cache (that data might be older) in a parallel ...
Andrey's user avatar
  • 141
2 votes
2 answers
1k views

Concise handling of async tasks with timeouts in c#

Often I have async functions that I want to be able to time out, this timeout is independent of the greater scope of the application. However the function should also take into consideration the ...
Adriaan's user avatar
  • 45
11 votes
5 answers
1k views

Finding reversed word pairs

I wrote this code to find opposites of words (i.e., words backwards). Input is a list of words. If this list contains a word + its opposite, then it should form a pair. The output should be a list of ...
planetx's user avatar
  • 111
3 votes
1 answer
348 views

Timeout thrower using multithreading

I designed a simple timeout thrower for a bluetooth protocol I am writing. If the packet is not received in a certain amount of time, then timeout is thrown. I made it to be as plug and play as ...
Aubrey Champagne's user avatar
2 votes
1 answer
219 views

Hackerrank problem -"Another Prime Problem"

I came across this issue in the problem titled: Another Prime Problem. Here's my solution with JavaScript which passed test case-1, but for other test cases it led to timeout. ...
Shardul Birje's user avatar
1 vote
0 answers
62 views

Why is my function timing out when run with a larger data set?

I am working on a Code Kata ...
MicFin's user avatar
  • 163
7 votes
3 answers
6k views

Find the smallest number greater than "n" with the same digit sum as "n"

Here is my code: ...
Kristada673's user avatar
1 vote
1 answer
61 views

Promise for request/response with timeout

Below is a piece of code that uses a promise for sending a request to a server, and to wait for an answer. Under normal conditions the server will always respond immediately, But of course you don't ...
bvdb's user avatar
  • 133
0 votes
2 answers
515 views

"Spread the Word" CodeChef challenge

I am solving the "Spread the Word" problem on CodeChef: Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest. There are \$N\$ people numbered 1 ...
Sandesh34's user avatar
  • 151
3 votes
2 answers
4k views

Check for timeout in wait() loop

I want to check for a condition in a guarded wait() loop with a user-specified total timeout, similar to how ...
Mark Jeronimus's user avatar
0 votes
1 answer
2k views

Promise-based fixed delay poller with timeout

I have the following functions for polling some function periodically with a timeout ...
geofflittle's user avatar
2 votes
0 answers
61 views

Write one string to a socket within 10 seconds or another string if the time is out

I have implemented a method which will send one data to the server if it (Raspberry Pi Pin Input HIGH, in this case) occurs within 10 seconds. If this doesn't happen within 10 seconds then I should ...
Khojiakbar's user avatar
3 votes
2 answers
2k views

Using await to break long-running processes

I have a Node.js app / Web API that runs on an Azure app service with a single CPU. One of the functions needs to run for a long time, perhaps tens of seconds, while the server should continue to ...
user avatar
2 votes
1 answer
1k views

Long running operation with timeout

I have a long running operation that I need to wait for or timeout. I have working code, but I would like your opinion on improving it. ...
Raskolnikov's user avatar
4 votes
2 answers
2k views

Implementing timeout of a resource (in this case a database connection)

I am currently having a problem with too many database connections. Therefore, I am trying to implement a database connection timeout. In the code below the changing of value of the shared resource ...
user2672165's user avatar
4 votes
4 answers
1k views

Hacker rank - Left rotation - PHP code feedback

Here is the problem description - https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem A left rotation operation on an array of size \$n\$ shifts each of the array's elements 1 ...
Prashanth kumar's user avatar
6 votes
2 answers
4k views

Java time-to-live collection

Here's a class I made in java. It's pretty simple, the description of what it does is in the comment. I'd appreciate any feedback. ...
Phoenix's user avatar
  • 267
5 votes
2 answers
4k views

Hackerrank: Gridland Metro

Problem statement The city of Gridland is represented as an n X m matrix where the rows are numbered from 1 to ...
Jianmin Chen's user avatar
  • 2,386
2 votes
1 answer
114 views

Blow the fuse if threshold exceeded

While implementing the Retry & Breaker patterns I decided that the Breaker does more then it should so I extracted two responsibilities into their own classes. Here they are. I stripped out the <...
t3chb0t's user avatar
  • 44k
-1 votes
1 answer
3k views

Example of Callback Hell [closed]

I am trying to come up with a minimal example of what is known as callback hell in JavaScript (so this would be a bad code review I guess). This is what I have so far, and I would like it to also run ...
Keno's user avatar
  • 117
18 votes
1 answer
18k views

Python Executer that kills processes after a timeout

Imagine you want to run a bunch of tasks in parallel, but you can't be sure that all of your tasks will eventually terminate or rather decide to eat up all your memory and CPU time. This should be ...
Klamann's user avatar
  • 351
1 vote
1 answer
125 views

TLE in APS - Amazing Prime Sequence in Python at Spoj

This series is similar to Fibonacci Series defined as : a[0] = a[1] = 0 and For n > 1, a[n] = a[n - 1] + f(n), where f(n) is ...
sarvajeetsuman's user avatar
2 votes
1 answer
793 views

Exponential backoff generator

Exponential backoff in the context of various networking protocols looks something like this: When a collision first occurs, send a “Jamming signal” to prevent further data being sent. ...
Dan Oberlam's user avatar
  • 7,724
3 votes
1 answer
2k views

Handling GetTickCount() overflow in timeouts

This is code which must run on XP, so no GetTickCount64, and which should correctly handle the value wrapping around after 49 days. Can it be improved? ...
Felix Dombek's user avatar
  • 1,081
1 vote
0 answers
192 views

Generic Timeout Handler

In a frontend Javascript project I have to implement a generic timeout mechanism for a set of asynchronous tasks that the program needs to perform. These are the conditions: The tasks are functions ...
Cristian Lupascu's user avatar
1 vote
1 answer
2k views

Decorating a timeout function

I've picked up the timeout-function below from ActiveState's recipes for Python2 and polished it for python3.4. Is there any leaner, less clunky way to write it? ...
root-11's user avatar
  • 512
6 votes
2 answers
31k views

Async task with timeout

I am calling a service outside of my control. My application must include a time out, so that if the call to the service takes too long, an appropriate time-out message is returned. ...
Jake's user avatar
  • 173
4 votes
2 answers
2k views

Window timeout alert

How can I improve this window timeout alert code? I need to add it to some third-party master page and don't want to add a separate file for it. It must be JS only and IE-8 supported. jsFiddle <...
Mathematics's user avatar
3 votes
1 answer
3k views

Controlling a Windows Service from a WPF app

I have a WPF Control Panel app, where I'm trying to stay close to an MVVM architecture. The control panel (the "the CP") is for a WCF service ("the Scheduler"), hosted in a Windows Service ("the Host")...
ProfK's user avatar
  • 193
7 votes
1 answer
3k views

Batch script to start the service in a gap of 10 min

I have created a batch script to start the services in a gap of 10 min. My batch file will start the service on the local system and then will wait for 10 mins and starts the service on another system ...
Vaibhav Veralkar's user avatar
1 vote
1 answer
319 views

Screen timeout/lock script

This is a script I made while having trouble with xautolock and dimming of the screen right before locking it. I would like some tips for making it a bit more robust and to know of any disadvantages ...
thabubble's user avatar
  • 143
8 votes
1 answer
3k views

Web service proxy that switches endpoint URLs in the event of a TimeoutException

I am creating a service (FaultTolerantCommunication) that wraps a call to a (web) service. Its responsibility is to switch the endpoint URL in the event of a ...
Sam Leach's user avatar
  • 295
11 votes
5 answers
70k views

Reading from a serial port

I'm receiving data from a serial port in C, using Serial Programming Guide for POSIX Operating Systems as a guide. The data I receive should be always 10 bytes in length but I want to be sure that, ...
user2018761's user avatar
1 vote
1 answer
116 views

Node.JS HTTP server displaying Google

I'm reading Professional Node.js: Building Javascript Based Scalable Software by Pedro Teixeira and created a web page responding with www.google.de. Could you take a look at my code and let me know ...
Maksim Dmitriev's user avatar
11 votes
1 answer
11k views

QNetworkReply network reply timeout helper

Since Qt still does not support to set timeouts on QNetworkRequest objects, I wrote this little wrapper class: ...
philk's user avatar
  • 219
3 votes
1 answer
6k views

JavaScript "recursion" via setTimeout

I understand that because of JavaScript's single-threaded execution, long loops or recursive calls could make the browser unresponsive while they execute. I thought about simulating recursion using <...
samfrances's user avatar
14 votes
3 answers
22k views

Timing out a method

I have created this extension method that can be used to run a function with a timeout applied to it. Is this a sensible way of doing it? ...
Rob White's user avatar
  • 281
3 votes
1 answer
2k views

Time Limit decorator

I have an interface named ICodeRunner, defined like this: ...
Cristian Lupascu's user avatar
7 votes
1 answer
578 views

Waiting for game server connection

...
Bart van Heukelom's user avatar
21 votes
3 answers
16k views

Determining if a connection has been made to a communications device

I am unsure if my use of Monitor.Wait and Monitor.Pulse is correct. It seems to work alright, but there is a nagging doubt I am ...
Andy's user avatar
  • 343