context: add a new context module, based on Golang's context, intended to be used in webservers (#9563)

This commit is contained in:
Ulises Jeremias Cornejo Fandos 2021-04-12 13:32:51 -03:00 committed by GitHub
parent b54188dfea
commit 07a6f4e445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 778 additions and 1 deletions

37
vlib/context/empty.v Normal file
View 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'
}