*There was a mistake in recognition in the first post, so this is a correction
If you write data=wait readData()
from the method with async, you will wait, but if you don't use the method, you will get an error saying that you can't use wait.
How can I use a method without async?
class FileTools{
Future<Map<String, List<String>>readData() async {
if(_file==null)setFile();
try{
String data = wait_file.readAsString();
return json.decode(data);
} catch(e){
// If encounter an error, return 0.
return null;
}
}
}
Determine the question as a way to invoke the asynchronous method readData()
from one other asynchronous operation
Asynchronous processing is available in some programming languages with the word async
/away
, but away
is used to call asynchronous functions from asynchronous functions and cannot be called from normal functions.(wait
can be called without but cannot receive callback, etc.)
Dart and JavaScript have asynchronous processing capabilities prior to async
/wait
deployment and are available.
Asynchronous processing in Dart appears to be called future
.To use it
The latter Future
API specifies the then()
method for callback acceptance(?) of asynchronous processing completion
final future=a_method()
future.then(val)=>print(val))
In addition, the Future
API of Dart corresponds to Promise
in JavaScript, so you may be able to refer to it
[Reference]
https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Using_promises
doSomething()
.then(result=>doSomethingElse(result))
.then(newResult=>doThirdThing(newResult))
.then(finalResult=>{
console.log(`Got the final result:${finalResult}`);
})
.catch(failureCallback);
569 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
903 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
580 PHP ssh2_scp_send fails to send files as intended
605 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.