mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
context: add a new context
module, based on Golang's context, intended to be used in webservers (#9563)
This commit is contained in:
parent
b54188dfea
commit
07a6f4e445
10 changed files with 778 additions and 1 deletions
37
vlib/context/empty.v
Normal file
37
vlib/context/empty.v
Normal file
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
|
||||
pub fn (ctx EmptyContext) deadline() ?time.Time {
|
||||
return none
|
||||
}
|
||||
|
||||
pub fn (ctx EmptyContext) done() chan int {
|
||||
ch := chan int{}
|
||||
defer {
|
||||
ch.close()
|
||||
}
|
||||
return ch
|
||||
}
|
||||
|
||||
pub fn (ctx EmptyContext) err() string {
|
||||
return ''
|
||||
}
|
||||
|
||||
pub fn (ctx EmptyContext) value(key string) ?voidptr {
|
||||
return none
|
||||
}
|
||||
|
||||
pub fn (ctx EmptyContext) str() string {
|
||||
if ctx == background {
|
||||
return 'context.Background'
|
||||
}
|
||||
if ctx == todo {
|
||||
return 'context.TODO'
|
||||
}
|
||||
return 'unknown empty Context'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue