Golang
How does the program behave when trying to write data to a bufferless channel that is initially empty?
Explain the principle of Pool Scheduling and its use in task management
Explain the concept of task separation between multiple threads or processes for system optimization. What does the term Work-Sharing mean?
What features of OOP in Go differ from implementations in other programming languages?
In which parts of an SQL query can aggregate functions be used to limit the result?
Tell us how you worked with data in your last project
What frameworks, standards, and packages do you use in Go?
How to correctly implement a safe system shutdown without data loss and with minimal downtime?
Why did you decide to change your job? What are you looking for?
There is a function `unpredictableFunc()`, which needs to be wrapped so that it executes with a timeout (for example, 1 second), and its execution time is logged. // There is a function that runs indefinitely long and returns a number. // Its body cannot be changed (imagine it as a network request). func unpredictableFunc() int64 { rnd := rand.Int63n(5000) time.Sleep(time.Duration(rnd) * time.Millisecond) return rnd } // You need to modify the wrapper function to work with a specified timeout (for example, 1 second). // If the "long" function completes within this time - great, return the result. // If not - return an error. The result of the execution in this case is not important. // // Additionally, you need to measure how long this function took to execute (just log it). // The signature of the wrapper function can be changed. func predictableFunc() (int64, error) { start := time.Now() ch := make(chan int64, 1) errCh := make(chan error, 1) go func() { result := unpredictableFunc() ch <- result }() select { case res := <-ch: duration := time.Since(start) log.Printf("Function executed in %s", duration) return res, nil case <-time.After(1 * time.Second): duration := time.Since(start) log.Printf("Function timed out after %s", duration) return 0, errors.New("timeout") } }
How does interaction between goroutines occur in Go?
What should be done if the server experiences delays due to high write activity?
Have you set up a domain name for a website or service?
How can you effectively update or retrieve values in a counter structure?
What is the result of the [] operator on a string data type?
Can you explain what the Reflect class in JavaScript is and what it is used for?
Is it necessary to allocate a separate structure for each running goroutine?
What characteristics are necessary for a hash function to serve as a key in a Map data structure?
Does NAT provide protection for transmitted data and connections?
How to extract the first n elements from an array?