-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcall.go
25 lines (21 loc) · 860 Bytes
/
call.go
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
// Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package toolbox
import (
"github.com/richardwilkes/toolbox/errs"
)
// Call the provided function, safely wrapped in a errs.Recovery() handler that logs any errors via slog.
func Call(f func()) {
CallWithHandler(f, func(err error) { errs.Log(err) })
}
// CallWithHandler calls the provided function, safely wrapped in a errs.Recovery() handler.
func CallWithHandler(f func(), errHandler func(err error)) {
defer errs.Recovery(errHandler)
f()
}