gitea: Queue unexpected type conversion

Description

q := queue.CreateSimpleQueue(
	graceful.GetManager().ShutdownContext(),
	"interface",
	func(data ...any) []any {
		for _, d := range data {
			fmt.Printf("<- %#v (%T)\n", d, d)
		}
		return nil
	},
)

go graceful.GetManager().RunWithCancel(q)

push := func(val any) {
	fmt.Printf("-> %#v (%T)\n", val, val)
	q.Push(val)
}

push(int64(1))
push(1)

Expected:

-> 1 (int64)
<- 1 (int64)
-> 1 (int)
<- 1 (int)

Actual:

-> 1 (int64)
<- 1 (float64)
-> 1 (int)
<- 1 (float64)

Somewhere there is an unexpected type conversion in the code.

@wxiaoguang You touched the queues last, it’s yours 😄

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Didn’t see any problem, what’s your code?

package main

import (
	"bytes"
	"encoding/gob"
	"fmt"
	"log"
)

type Sub struct {
	V any
}

type Msg struct {
	V1, V2 any
}

func main() {
	gob.Register(Sub{})

	buf := new(bytes.Buffer)
	enc := gob.NewEncoder(buf)
	dec := gob.NewDecoder(buf)

	err := enc.Encode(Msg{1, Sub{2}})
	if err != nil {
		log.Fatal("encode error:", err)
	}

	var m Msg
	err = dec.Decode(&m)
	if err != nil {
		log.Fatal("decode error 1:", err)
	}
	fmt.Printf("%#v\n", m)
}
main.Msg{V1:1, V2:main.Sub{V:2}}