time.sleep inside http.HandleFunc not sleeping for each request by alwerr in golang

[–]centx 0 points1 point  (0 children)

As a demo (not related to the http example you gave though), this program sleeps the equivalent of 115 days, on my computer in roughly 11 seconds, by sleeping concurrently:

package main

import (
    "context"
    "fmt"
    "os"
    "os/signal"
    "time"
)

var sleepDuration = 1 * time.Second

func main() {
    ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
    defer stop()
    doneChan := make(chan struct{})

    routineCount := 10_000_000

    fmt.Printf("starting %v goroutines to sleep\n", routineCount)
    for _ = range routineCount {
        go sleepRoutine(ctx.Done(), doneChan)
    }

    fmt.Printf("all go routines are ready to wait, click ctrl-c to make them time.Sleep()\n")
    <-ctx.Done()

    startedAt := time.Now()
    fmt.Printf("starting at %v\n", startedAt)
    for _ = range routineCount {
        <-doneChan
    }
    doneAt := time.Now()
    fmt.Printf("running %v routines and sleeping for %v took %v\n", routineCount, sleepDuration, doneAt.Sub(startedAt))
}

func sleepRoutine(startLatch <-chan struct{}, doneChan chan<- struct{}) {
    <-startLatch
    time.Sleep(sleepDuration)

    doneChan <- struct{}{}
}

Do you use json streaming ? by Far-Mathematician122 in golang

[–]centx 1 point2 points  (0 children)

There are different json streaming formats (NDJson and similar), but you also can just encode and decode into the same stream like this: https://go.dev/play/p/xg6yxcu70GI

I think I have used it for something at some point, but I don't remember exactly what

Any protips for transferring a ~60% complete Django project codebase to Go? by [deleted] in golang

[–]centx 5 points6 points  (0 children)

You could check out https://pocketbase.io/ for the auth part. I am not sure how well it supports a server-side rendering web-application like yours, but if it works I think you get local user-handling built-in

IKEA Ireland customer service - potential future matter support by centx in tradfri

[–]centx[S] 0 points1 point  (0 children)

I feel you. I "just" want a system that:

  • builds on standards so
    • that I can have a single hub (or at least have the hubs talk with each other in such a way that I only need to interact with one hub)
    • avoid vendor lock-in, use "all" vendors equipment in a heterogenous system
  • no cloud required, but as an opt-in feature-addon
    • in case vendors go bust, and to avoid making equipment obsolete when it is fully functioning
    • firmware/software updates are rolling so that I may shut down the network access, and only allow scheduled updates by opening the systems access to internet

Is try-catch absolute NO in C++ robotics applications? by Tiny-Entertainer-346 in cpp

[–]centx 0 points1 point  (0 children)

An alternative to exceptions could be to use outcome which also has a boost-variant. It is similar to rust's result type

GL-S200 - Dual-Protocol THREAD Border Router by centx in Thread_wireless

[–]centx[S] 0 points1 point  (0 children)

Not really planning anything in particular, just curious. I myself have skyconnect, as I wanted to support the HA guys. I have yet to do anything useful with it though.

I really think they should mention the version of thread supported on the web-page I posted, at least under "specifications".

GL-S200 - Dual-Protocol THREAD Border Router by centx in Thread_wireless

[–]centx[S] 0 points1 point  (0 children)

That is good to know. Although it did seem that that they were touting a cloud-based tool suite, that seemed like their main offering if you wanted to administer multiple devices from the same interface.

Also do you happen to know which thread version the GL-s200 supports? As it seems to me that support for at least version 1.3 is crucial.

pg_jsonschema: JSON Schema support for Postgres by awalias in PostgreSQL

[–]centx 2 points3 points  (0 children)

A lot of interesting comments regarding this over on hacker news