runZoned<R> 静态方法

R runZoned<R>(
  1. R body()?,
  2. {
    1. Directory createDirectory(
    )?,
  3. String
  4. Directory getCurrentDirectory()?,
    1. Directory createDirectory(
    )?,
  5. void setCurrentDirectory(
  6. Directory getSystemTempDirectory()?,
    1. Directory createDirectory(
    )?,
  7. File createFile(
    1. Directory createDirectory(
    )?,
  8. Future<FileStat> stat(
    1. Directory createDirectory(
    )?,
  9. FileStat statSync(
    1. Directory createDirectory(,
    2. Directory createDirectory(
    )?,
  10. Future<bool> fseIdentical(
    1. Directory createDirectory(,
    2. Directory createDirectory(
    )?,
  11. bool fseIdenticalSync(
    1. Directory createDirectory(,
    2. Future<FileSystemEntityType> fseGetType(
    )?,
  12. bool
    1. Directory createDirectory(,
    2. Future<FileSystemEntityType> fseGetType(
    )?,
  13. FileSystemEntityType fseGetTypeSync(
    1. Directory createDirectory(,
    2. Stream<FileSystemEvent> fsWatch(,
    3. Future<FileSystemEntityType> fseGetType(
    )?,
  14. int
  15. bool fsWatchIsSupported()?,
    1. Directory createDirectory(
    )?,
  16. Link createLink(
    1. Future<Socket> socketConnect(,
    2. Stream<FileSystemEvent> fsWatch(, {
    3. dynamic
    4. dynamic sourceAddress,
    5. int sourcePort,
    })?,
  17. Duration? timeout,
    1. Future<Socket> socketConnect(,
    2. Stream<FileSystemEvent> fsWatch(, {
    3. dynamic
    4. dynamic sourceAddress,
    })?,
  18. Future<ConnectionTask<Socket>> socketStartConnect(
    1. Future<Socket> socketConnect(,
    2. Stream<FileSystemEvent> fsWatch(, {
    3. Future<ServerSocket> serverSocketBind(
    4. int backlog,
    5. bool v6Only,
    })?,
  19. Stdin stdin()?,
  20. Stdout stdout()?,
  21. Stdout stderr()?,
})

使用提供的覆盖设置,在新的 Zone 中运行 body

有关可选参数的功能信息,请参阅 IOOverrides 对应方法的文档。

实现

static R runZoned<R>(R body(),
    {
    // Directory
    Directory Function(String)? createDirectory,
    Directory Function()? getCurrentDirectory,
    void Function(String)? setCurrentDirectory,
    Directory Function()? getSystemTempDirectory,

    // File
    File Function(String)? createFile,

    // FileStat
    Future<FileStat> Function(String)? stat,
    FileStat Function(String)? statSync,

    // FileSystemEntity
    Future<bool> Function(String, String)? fseIdentical,
    bool Function(String, String)? fseIdenticalSync,
    Future<FileSystemEntityType> Function(String, bool)? fseGetType,
    FileSystemEntityType Function(String, bool)? fseGetTypeSync,

    // _FileSystemWatcher
    Stream<FileSystemEvent> Function(String, int, bool)? fsWatch,
    bool Function()? fsWatchIsSupported,

    // Link
    Link Function(String)? createLink,

    // Socket
    Future<Socket> Function(dynamic, int,
            {dynamic sourceAddress, int sourcePort, Duration? timeout})?
        socketConnect,
    Future<ConnectionTask<Socket>> Function(dynamic, int,
            {dynamic sourceAddress, int sourcePort})?
        socketStartConnect,

    // ServerSocket
    Future<ServerSocket> Function(dynamic, int,
            {int backlog, bool v6Only, bool shared})?
        serverSocketBind,

    // Standard Streams
    Stdin Function()? stdin,
    Stdout Function()? stdout,
    Stdout Function()? stderr}) {
  // Avoid building chains of override scopes. Just copy outer scope's
  // functions and `_previous`.
  var current = IOOverrides.current;
  _IOOverridesScope? currentScope;
  if (current is _IOOverridesScope) {
    currentScope = current;
    current = currentScope._previous;
  }
  IOOverrides overrides = new _IOOverridesScope(
    current,
    // Directory
    createDirectory ?? currentScope?._createDirectory,
    getCurrentDirectory ?? currentScope?._getCurrentDirectory,
    setCurrentDirectory ?? currentScope?._setCurrentDirectory,
    getSystemTempDirectory ?? currentScope?._getSystemTempDirectory,

    // File
    createFile ?? currentScope?._createFile,

    // FileStat
    stat ?? currentScope?._stat,
    statSync ?? currentScope?._statSync,

    // FileSystemEntity
    fseIdentical ?? currentScope?._fseIdentical,
    fseIdenticalSync ?? currentScope?._fseIdenticalSync,
    fseGetType ?? currentScope?._fseGetType,
    fseGetTypeSync ?? currentScope?._fseGetTypeSync,

    // _FileSystemWatcher
    fsWatch ?? currentScope?._fsWatch,
    fsWatchIsSupported ?? currentScope?._fsWatchIsSupported,

    // Link
    createLink ?? currentScope?._createLink,

    // Socket
    socketConnect ?? currentScope?._socketConnect,
    socketStartConnect ?? currentScope?._socketStartConnect,

    // ServerSocket
    serverSocketBind ?? currentScope?._serverSocketBind,

    // Standard streams
    stdin ?? currentScope?._stdin,
    stdout ?? currentScope?._stdout,
    stderr ?? currentScope?._stderr,
  );
  return dart_async
      .runZoned<R>(body, zoneValues: {_ioOverridesToken: overrides});
}