Go Context原理及其典型适用场景Context原理及其适用场景 随手记 李帅(飞雪无情) n 常见并发模式 n Context实现原理 n TLS VS Context n 典型适用场景 大纲 Channel Fan-in func fanIn(sum1, sum2 <-chan int) <-chan int { sum := make(chan int) go func() { for {sum <- <-sum1} } } Context l 一个任务,需要多个goroutine完成 l 一个请求,会触发好多个goroutine做不同的事情 l 如果我们的任务终止了,请求取消了,这些正在运行 的goroutine怎么办? l 使用Context来简化这些操作 Context能做什么 u 手动、定时、超时发出取消信号 u 跨API传值 u 控制生成Context树结构(Context链) Context main() { rootCtx := context.Background() ctx, cancel := context.WithCancel(rootCtx) go watch(ctx) go watch(ctx) time.Sleep(1 * time.Second) cancel() } func watch(ctx context.Context) { for { select {0 码力 | 32 页 | 4.62 MB | 1 年前3
Java EE 企业应用系统开发 - HTTP 响应处理编程响应对象 响应对象功能和方法 HTTP 响应的内容 在 Web 服务器接收请求处理后,向客户端发送 HTTP 响应 (Response)。 O 响应的内容 ▶ 响应状态(Status Code) ▶ 响应头(Response Header) ▶ 响应体(Response Body) 大纲 HTTP 响应的内容 HTTP 响应对象 响应对象功能和方法 HTTP 响应状态行 表明响应的状态信息,如成功、失败、错误。 告知客户可以接收的字符集:Accept-Charset 3. 响应的字符编码集:Accept-Encoding 4. 响应体的 MIME 类型:Content-Type 5. 响应体的语言类型:Context-Language 6. 响应体的长度和字节数:Content-Length 7. 通知客户端到期时间:Expires 8. 缓存情况:Cache-Control 9. 重定向到另一个 URL 向客户端发送指定的错误信息码,可以是任意定义的整数。 1 response.setCharacterEncoding("GBK"); 2 response.sendError(580); O public void sendError(int sc, String msg) throws IOException 向客户端发送指定的错误信息码和自定义状态消息。 1 response.setCharacterEncoding("GBK");0 码力 | 26 页 | 575.28 KB | 1 年前3
Flask Documentation (1.1.x)Production Keep Developing! Templates Jinja Setup Standard Context Standard Filters Controlling Autoescaping Registering Filters Context Processors Testing Flask Applications The Application The Testing Test Logging In and Out Test Adding Messages Other Testing Tricks Faking Resources and Context Keeping the Context Around Accessing and Modifying Sessions Testing JSON APIs Testing CLI Commands Application Request Context Decorator Based Signal Subscriptions Core Signals Pluggable Views Basic Principle Method Hints Method Based Dispatching Decorating Views Method Views for APIs The Application Context Purpose0 码力 | 428 页 | 895.98 KB | 1 年前3
Flask Documentation (1.1.x). . . . . . . . 86 1.14 The Application Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 1.15 The Request Context . . . . . . . . . . . . . . . . . . . . a request in order to stay threadsafe. This approach is convenient, but requires a valid request context for dependency injection or when attempting to reuse code which uses a value pegged to the request use the test_request_context() method to try out url_for(). test_request_context() tells Flask to behave as though it’s handling a request even while we use a Python shell. See Context Locals. from flask0 码力 | 291 页 | 1.25 MB | 1 年前3
Falcon v3.0.0 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 344 页 | 1.16 MB | 1 年前3
Falcon v3.0.1 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 344 页 | 1.16 MB | 1 年前3
Falcon v3.1.1-b3 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 378 页 | 1.29 MB | 1 年前3
Falcon v3.1.1-b1 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 378 页 | 1.29 MB | 1 年前3
Falcon v3.1.1-a Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 378 页 | 1.29 MB | 1 年前3
Falcon v3.1.0 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4.2 Request & Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 5.4.3 WebSocket Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs Highly-optimized, extensible code base • Easy access to headers and bodies through request and response objects • DRY request processing via middleware components and hooks • Strict adherence to RFCs0 码力 | 362 页 | 1.29 MB | 1 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100













