summaryrefslogtreecommitdiffstats
path: root/test/typeparam/issue50561.dir/diameter.go
blob: 2bfe92405da520ff78bc5ef3925269ab90d7296f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package diameter

type Runnable interface {
	Run()
}

// RunnableFunc is converter which converts function to Runnable interface
type RunnableFunc func()

// Run is Runnable.Run
func (r RunnableFunc) Run() {
	r()
}

type Executor interface {
	ExecuteUnsafe(runnable Runnable)
}

type Promise[T any] interface {
	Future() Future[T]
	Success(value T) bool
	Failure(err error) bool
	IsCompleted() bool
	Complete(result Try[T]) bool
}

type Future[T any] interface {
	OnFailure(cb func(err error), ctx ...Executor)
	OnSuccess(cb func(success T), ctx ...Executor)
	Foreach(f func(v T), ctx ...Executor)
	OnComplete(cb func(try Try[T]), ctx ...Executor)
	IsCompleted() bool
	//	Value() Option[Try[T]]
	Failed() Future[error]
	Recover(f func(err error) T, ctx ...Executor) Future[T]
	RecoverWith(f func(err error) Future[T], ctx ...Executor) Future[T]
}

type Try[T any] struct {
	v   *T
	err error
}

func (r Try[T]) IsSuccess() bool {
	return r.v != nil
}

type ByteBuffer struct {
	pos       int
	buf       []byte
	underflow error
}

// InboundHandler is extends of uclient.NetInboundHandler
type InboundHandler interface {
	OriginHost() string
	OriginRealm() string
}

type transactionID struct {
	hopID uint32
	endID uint32
}

type roundTripper struct {
	promise map[transactionID]Promise[*ByteBuffer]
	host    string
	realm   string
}

func (r *roundTripper) OriginHost() string {
	return r.host
}
func (r *roundTripper) OriginRealm() string {
	return r.realm
}

func NewInboundHandler(host string, realm string, productName string) InboundHandler {
	ret := &roundTripper{promise: make(map[transactionID]Promise[*ByteBuffer]), host: host, realm: realm}

	return ret
}