如何实现看起来像模仿async/await的异步代码? [英] How to implement asynchronous code that looks synchronous mimicking async / await?

查看:118
本文介绍了如何实现看起来像模仿async/await的异步代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

否则,我想依靠epoll(或类似方法)来编写异步网络代码,该代码看起来像不依赖回调的常规代码.

Otherwise said, I want to rely on epoll (or similar) to write asynchronous network code that looks like regular code that is without relying on callbacks.

代码必须看起来像同步代码,但是与同步代码不同,它不是阻塞等待网络io,而是必须挂起当前的协程,并在文件描述符准备好后重新启动.

The code must look like synchronous code but unlike synchronous code instead of blocking to wait for network io, it must suspend the current coroutine and restart it when the file descriptor is ready.

推荐答案

如果您使用的是chez-scheme,则有 chez-a-sync .它使用POSIX poll而不是epoll(epoll是Linux特定的). guile-a-sync2也可用于guile-2.2/3.0.

If you are using chez-scheme, there is chez-a-sync. It uses POSIX poll rather than epoll (epoll is linux specific). guile-a-sync2 is also available for guile-2.2/3.0.

这篇关于如何实现看起来像模仿async/await的异步代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆