How Meta Made Debugging Async Code Easier with Coroutines and Senders
… … Stack Traces for Async Code are Unhelpful Threadpool threads: #0 process_file(...) #5 pool.run() #10 __clone … … IO Thread: #0 async_read_some_at(...) #3 ctx Threadpool threads: #0 process_file(...) #5 pool.run() #10 … IO Thread: … #0 async_read_some_at(...) #3 ctx.run() #5 __clone … … Main thread: #0 unifex::sync_wait( … #0 async_read_some_at(...) … #12 unifex::sync_wait(...) #16 main() #19 __libc_start_main() … … Async Stacks are BetterStructured Concurrency Makes Async Stacks Possible0 码力 | 131 页 | 907.41 KB | 5 月前3WebAssembly 简介 - 陈思衡
之类的 async runtime 中执行一些特别的 WASM 时就会遇到 WASM 阻塞 tokio 最终导致服务不可用的情况。 阻塞示例 WASM 使用场景和问题 利用语言本身 Async 机制 因为 Rust 的 async 机制是无栈协程,会将 async 部分在编译时隐式转换成一个 Future。 所以我们可以利用这一点来实现一个 Async 的 Wasm。 Async Wasm Photo / image / chart 利用本身 Async 机制 自行实现 Async Runtime Async 的 Wasm • 在 wasm 中把 future 存入固定内存处。 • 导出 poll 函数给 host 调用。 • 把 host function 包装成自定义 Future。 • 实现简单 利用本身 Async 机制 优点 • 方案不通用(wasm 局限于某一种语言) 无法与现有生态配合 缺点 Async 的 Wasm 基于 fiber / ucontext Async Wasm 解决方案 wasmtime-fiber 是一个通过内联汇编,保存当前寄存 器和栈数据来实现有栈协程的 rust 库。 wasmtime-fiber Ucontext 和 fiber 功能相同,但是 linux 的系统库。 ucontext 执行流程 Async Wasm 解决方案0 码力 | 24 页 | 773.46 KB | 1 年前3Deciphering C++ Coroutines
Cheat Sheet - Awaitable 1 struct Awaitable { 2 bool await_ready (); 3 auto await_suspend (std:: coroutine_handle < promise_type >); 4 auto await_resume (); 5 };12/55 Cheat Sheet: Map of Coroutine Land13/55 Task18/55 Threads - A straightforward solution std::futurespawn_task () { return std:: async( outer_function ); }18/55 Threads - A straightforward solution main() spawn task()18/55 Threads auto data = co_await async_io (...); co_return IoResult :: from_io_data(data ); }24/55 Suspending nested coroutines Async inner_function () { auto data = co_await async_io (...); co_return 0 码力 | 156 页 | 1.79 MB | 5 月前3Coroutines and Structured Concurrency in Practice
demonstrated to justify switchingCallbacks vs coroutines // read length auto len = make_unique(); async_read(socket, buffer(len.get(), sizeof(int32_t)), [len = move(len)](auto ec, size_t len1){ && len1 == sizeof(int32_t)) { // read data auto buf = make_unique (*len); async_read(socket, buffer(buf.get(), *len), [buf = move(buf), len = *len] (auto // read length int32_t len; co_await async_read(s, buffer(&len, sizeof(len)), use_awaitable); // read data auto buf = make_unique (len); co_await async_read(s, buffer(buf.get(), len) 0 码力 | 103 页 | 1.98 MB | 5 月前3websockets Documentation Release 9.0
import asyncio import websockets async def hello(): uri = "ws://localhost:8765" async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") await websocket.recv() asyncio.get_event_loop() server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) start_server = websockets.serve(echo, "localhost" example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 81 页 | 352.88 KB | 1 年前3ThinkJS 2.2 中文文档
介绍 ThinkJS 是一款使用 ES6/7 特性全新开发的 Node.js MVC 框架,使用 ES7 中 async/await ,或者 ES6 中的 */yield 特性彻底解决了 Node.js 中异步嵌套的问题。同时吸收了国内外众多框架的设 计理念和思想,让开发 Node.js 项目更加简单、高效。 使用 ES6/7 特性来开发项目可以大大提高开发效率,是趋势所在。并且新版的 Node 所有的特性,无需担心哪些特性当前版本不支 持。尤其是使用 async/await 或者 */yield 来解决异步回调的问题。 //user controller, home/controller/user.js export default class extends think.controller.base { //login action async loginAction(self){ //这⾥里里可以通过post⽅方法获取所有的数据,数据已经在logic⾥里里做了了校验 let data = this.post(); //⽤用户名去匹配数据库中对应的条⽬目 let result = await this.model('user').where({name: data.name}).find(); if(!validateLogin(result)){ return this0 码力 | 277 页 | 3.61 MB | 1 年前3JavaScript Promiseの本 v2
............................ 108 Chapter.5 - Async Function ................................................................................... 116 Async Functionとは .................................. ..................................... 116 Async Functionの構文 ..................................................................................... 119 await 式 ......................................... .................................................................. 121 Async Functionと配列 ..................................................................................... 124 Promises API Reference0 码力 | 137 页 | 1.17 MB | 1 年前3websockets Documentation Release 5.0
”: #!/usr/bin/env python import asyncio import websockets async def hello(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") asyncio.get_event_loop().run_until_complete( server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) asyncio.get_event_loop().run_until_complete( example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 56 页 | 245.43 KB | 1 年前3Comprehensive Rust(Persian ) 202412
. . . . . . . 351 XIV � � � � � � � : � � � 357 63 � � � � � � � � 358 64 � � � � � Async 359 64.1 async/await . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 64.2 Futures . . . . . . . . . . . . . . . . . 362 65 � � � � � � � � Control Flow 363 65.1 � � � � � � � � Async . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 65.2 Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 66.3 � � � � Async . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 66.4 � � � . . . . .0 码力 | 393 页 | 987.97 KB | 10 月前3websockets Documentation Release 6.0
”: #!/usr/bin/env python import asyncio import websockets async def hello(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") asyncio.get_event_loop().run_until_complete( server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) asyncio.get_event_loop().run_until_complete( example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 58 页 | 253.08 KB | 1 年前3
共 974 条
- 1
- 2
- 3
- 4
- 5
- 6
- 98