There are 2 problems in this code.
Problem 1: using async and sync code in one place. Here is an example snippet (for testing I removed fetch
, but replaced it with its data, because your fetch is not working in snippet here).
Compare results of DATA1
and DATA2
. The first one is sync, the second - async. You can see, that your sync variant is not working. So, you need async (using .then
).
const getData = async() => {
//console.log("Processing");
//const request = await fetch("http://46.101.95.202/api/repos/RxJava/");
//const data = await request.json();
const data = {
"key": "RxJava", "name": "RxJava", "language": "java",
"path": "/RxJava_c", "links": { "self": "/api/repos/RxJava/" },
"contents": [{
"path": "/RxJava_c/docs", "name": "docs",
"type": "directory",
"follow": "/api/repos/RxJava?data_path=/RxJava_c/docs"
},
{
"path": "/RxJava_c/gradle", "name": "gradle",
"type": "directory",
"follow": "/api/repos/RxJava?data_path=/RxJava_c/gradle"
},
{
"path": "/RxJava_c/src", "name": "src",
"type": "directory",
"follow": "/api/repos/RxJava?data_path=/RxJava_c/src"
}
]};
return data;
};
console.log("DATA1 =", getData());
getData().then((mydata) => {
console.log("DATA2 =", mydata);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…