2021-04-16 11:54:28 +03:00
|
|
|
// This module defines the Context type, which carries deadlines, cancellation signals,
|
|
|
|
// and other request-scoped values across API boundaries and between processes.
|
2021-09-27 17:52:20 +03:00
|
|
|
// Based on: https://github.com/golang/go/tree/master/src/context
|
2021-04-16 11:54:28 +03:00
|
|
|
// Last commit: https://github.com/golang/go/commit/52bf14e0e8bdcd73f1ddfb0c4a1d0200097d3ba2
|
2021-04-12 19:32:51 +03:00
|
|
|
module context
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
// An EmptyContext is never canceled, has no values, and has no deadline. It is not
|
|
|
|
// struct{}, since vars of this type must have distinct addresses.
|
|
|
|
pub type EmptyContext = int
|
|
|
|
|
2021-09-27 17:52:20 +03:00
|
|
|
pub fn (ctx &EmptyContext) deadline() ?time.Time {
|
2021-04-12 19:32:51 +03:00
|
|
|
return none
|
|
|
|
}
|
|
|
|
|
2021-09-27 17:52:20 +03:00
|
|
|
pub fn (ctx &EmptyContext) done() chan int {
|
2021-04-12 19:32:51 +03:00
|
|
|
ch := chan int{}
|
|
|
|
defer {
|
|
|
|
ch.close()
|
|
|
|
}
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
2021-09-27 17:52:20 +03:00
|
|
|
pub fn (ctx &EmptyContext) err() IError {
|
|
|
|
return none
|
2021-04-12 19:32:51 +03:00
|
|
|
}
|
|
|
|
|
2021-09-27 17:52:20 +03:00
|
|
|
pub fn (ctx &EmptyContext) value(key Key) ?Any {
|
2021-04-12 19:32:51 +03:00
|
|
|
return none
|
|
|
|
}
|
|
|
|
|
2021-09-27 17:52:20 +03:00
|
|
|
pub fn (ctx &EmptyContext) str() string {
|
2021-04-12 19:32:51 +03:00
|
|
|
if ctx == background {
|
|
|
|
return 'context.Background'
|
|
|
|
}
|
|
|
|
if ctx == todo {
|
|
|
|
return 'context.TODO'
|
|
|
|
}
|
|
|
|
return 'unknown empty Context'
|
|
|
|
}
|