You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
455 B
28 lines
455 B
package threading |
|
|
|
import ( |
|
"bytes" |
|
"git.diulo.com/mogfee/kit/core/rescue" |
|
"runtime" |
|
"strconv" |
|
) |
|
|
|
func GoSafe(fn func()) { |
|
go RunSafe(fn) |
|
} |
|
|
|
func RoutineId() uint64 { |
|
b := make([]byte, 64) |
|
b = b[:runtime.Stack(b, false)] |
|
b = bytes.TrimPrefix(b, []byte("goroutine ")) |
|
b = b[:bytes.IndexByte(b, ' ')] |
|
// if error, just return 0 |
|
n, _ := strconv.ParseUint(string(b), 10, 64) |
|
return n |
|
} |
|
|
|
func RunSafe(fn func()) { |
|
defer rescue.Recover() |
|
|
|
fn() |
|
}
|
|
|