Fanx language 3.3 is released, using async-await to solve asynchronous IO problems

Fanx is an object-oriented functional programming language.  Version 3.3 mainly enhances the async-await function and tries to use it to solve asynchronous IO problems.

Before async-await was used in the network request module of the client UI framework, this time it was used on the server side. Traditional blocking IO has low performance, while asynchronous IO has many callbacks, making the code difficult to read. Using async-await allows us to write code in a manner similar to blocking IO, while having the performance of asynchronous IO.

The current network framework supports the basic http protocol, sample code:

const class HttpTestServer : HttpHandler {

  override async Void onHttpService(HttpReq req, HttpRes res) {
    res.headers["Content-Type"] = "text/html; charset=utf-8"

    buf := NioBuf.makeMem(1024)
    buf.printLine("<html>
                        <body>Hello World $req.uri</body>
                       </html>")
    buf.flip
    await res.writeChunk(buf)
  }

  static Void main() {
    Server {
      port = 8080
      handler = HttpTestServer()
    }.start
  }
}

In the code, when running to await, the current task is paused and handed over to the selector thread to monitor IO events. The current thread is not blocked but continues to process other connection tasks. When the selector finds that the event is ready, it is notified to resume running the task.

Whether it is web development or App development, Fanx language can use the same language in front-end and back-end development, avoiding the gap between them.

Guess you like

Origin www.oschina.net/news/119466/fax-3-3-released