What thread / isolate does flutter run IO operations on?

后端 未结 1 1697
春和景丽
春和景丽 2021-01-19 03:40

In flutter when using the http package or doing general IO operations for example

import \'package:http/http.dart\' as http;

http.Response response = await         


        
1条回答
  •  心在旅途
    2021-01-19 04:08

    Dart handles IO requests with a thread pool. To find out I had to clone the Dart SDK and look into the source code, as I couldn't find answer from the docs.

    When an IO method is called, the File implementation _File class method is called. It creates a Port to native code (IOService_NewServicePort) and sends the IO request id and args to native code. The native code handles the IO requests with a thread pool (runtime\vm\native_api_impl.cc#Dart_NewNativePort), submiting a task into the thread pool. Then the native code returns all the way back to Dart code and _File returns a future object. After the IO operation is done, the result is sent back from native to Dart by the port created before. This triggers a handler registered on the port and the future is resolved.

    0 讨论(0)
提交回复
热议问题