Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Expo FileSystem.writeastringasync不';Don’不要像承诺一样行事_Javascript_React Native_Promise_Expo - Fatal编程技术网

Javascript Expo FileSystem.writeastringasync不';Don’不要像承诺一样行事

Javascript Expo FileSystem.writeastringasync不';Don’不要像承诺一样行事,javascript,react-native,promise,expo,Javascript,React Native,Promise,Expo,我正在使用Expo.writeastringasync()函数 (文件:)。 我注意到它需要不同的时间来处理不同大小的文件(正如预期的那样),但是无法知道它何时完成,因为它不返回任何内容。因此,如果我必须在写入文件后访问它,我可能会发现它是空的,因为它可能还在写入 完成后有没有办法收到答复?像一个正常的承诺,然后抓住 注意:我已经尝试过了,但是没有成功。我可以看出API文档有误导性,因为它们没有指定返回类型 事实上,API调用被定义为async函数(请参阅): 或 export async fu

我正在使用Expo.writeastringasync()函数 (文件:)。 我注意到它需要不同的时间来处理不同大小的文件(正如预期的那样),但是无法知道它何时完成,因为它不返回任何内容。因此,如果我必须在写入文件后访问它,我可能会发现它是空的,因为它可能还在写入

完成后有没有办法收到答复?像一个正常的承诺,然后抓住


注意:我已经尝试过了,但是没有成功。

我可以看出API文档有误导性,因为它们没有指定返回类型

事实上,API调用被定义为
async
函数(请参阅):

export async function writeAsStringAsync(
  fileUri: string,
  contents: string,
  options: WritingOptions = {}
): Promise<void> {
  // ...
}
await Expo.writeAsStringAsync(fileUri, contents, options);
// do something when write is finished 
// you can catch errors with try/catch clause
Expo.writeAsStringAsync(fileUri, contents, options).then(
  () => { /* do something when write is finished */ }
).catch(err => { /* handle errors */ }