Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions pkl/atomic.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
// Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,7 @@
package pkl

import (
"math/rand"
"sync"
"sync/atomic"
"time"
)

type atomicBool struct {
Expand All @@ -34,19 +31,3 @@ func (a *atomicBool) get() bool {
func (a *atomicBool) set(value bool) {
a.Store(value)
}

var randPool = &sync.Pool{
New: func() interface{} {
return rand.New(rand.NewSource(time.Now().UnixNano()))
},
}

type atomicRandom struct{}

func (a *atomicRandom) Int63() int64 {
r := randPool.Get().(*rand.Rand)
defer randPool.Put(r)
return r.Int63()
}

var random = &atomicRandom{}
3 changes: 2 additions & 1 deletion pkl/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"log"
"math/rand/v2"
"net/url"
"sync"

Expand Down Expand Up @@ -128,7 +129,7 @@ func (e *evaluator) EvaluateExpressionRaw(ctx context.Context, source *ModuleSou
if e.Closed() {
return nil, fmt.Errorf("evaluator is closed")
}
requestId := random.Int63()
requestId := rand.Int64()
ch := make(chan *msgapi.EvaluateResponse)
e.pendingRequests.Store(requestId, ch)
interrupted, nevermind := e.manager.interrupted(e.evaluatorId)
Expand Down
5 changes: 3 additions & 2 deletions pkl/evaluator_manager.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
// Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@ import (
"context"
"errors"
"log"
"math/rand/v2"
"net/url"
"sync"

Expand Down Expand Up @@ -106,7 +107,7 @@ func (m *evaluatorManager) NewEvaluator(ctx context.Context, opts ...func(option
return nil, err
}
var newEvaluatorRequest msgapi.OutgoingMessage
requestId := random.Int63()
requestId := rand.Int64()
msg := o.toMessage()
msg.RequestId = requestId
newEvaluatorRequest = msg
Expand Down