我希望我的提取请求有某种重试系统,如果它基于响应的 HTTP 代码(例如:不是 200)以某种方式失败。它看起来像这样:
fetch('someURLWithAJSONfile/file.json')
.then(function (res) {
console.log(res.status);
if (res.status !== 200) {
console.log("There was an error processing your fetch request. We are trying again.");
// Recursive call to same fetch request until succeeds
} else {
return res.json();
}
}).then(function (json) {
data = json;
}).catch(function (err) {
console.log(`There was a problem with the fetch operation: ${err.message}`);
});
Run Code Online (Sandbox Code Playgroud)
有没有办法将获取请求放入自定义 Promise 中,并使其在检查其 http 响应状态后调用自身?
我有一个 Reactjs SPA,其文件结构如下所示:
\n\n\n\n在该应用程序中有一个简单的组件(Resume.js),我希望用户能够在浏览器中查看/下载pdf文件(resume_english.pdf)。然而,我无法在本地或在我计划托管 SPA 的 GitHub 页面中执行此操作。它总是将我重定向到主页。
\n\nResume.js看起来像这样:
\n\nimport React, {Component} from \'react\';\n\nclass Resume extends Component {\n constructor(props) {\n super(props);\n\n this.state = {};\n }\n\n render() {\n return (\n <div className={\'resume-container\'}>\n <div id={\'resume-pdf\'}>You can view, download and print my r\xc3\xa9sum\xc3\xa9 in pdf format in <a\n href={\'./public/resume_english.pdf\'}>English</a> and <a href={\'#\'}>Spanish</a></div>\n </div>\n );\n }\n}\n\nexport default Resume;\n
Run Code Online (Sandbox Code Playgroud)\n\n关于如何解决它可能有什么问题有什么想法吗?我已经尝试过像这样导入,但没有成功。
\n我需要交换给定两个位置(i,j)的列表元素来实现TSP的2-opt启发式,并发现这个问题建议使用rotatef
.
但是,当我尝试使用它时,我无法理解它的行为.
这段代码令我头疼:
(setq loop '(A B C D E F))
> (A B C D E F)
;; Original copy saved in loop
(setq new_tour loop)
(format t "ORIGINAL LOOP: " loop)
> LOOP: (A B C D E F)
(format t "NEW_TOUR: " new_tour)
> NEW_TOUR: (A B C D E F)
(rotatef (nth 0 new_tour) (nth 1 new_tour))
(format t "NEW_TOUR IS NOW: ~a~%" new_tour)
> NEW_TOUR IS NOW: (B A C D …
Run Code Online (Sandbox Code Playgroud) 我有一个程序从一个非常大的二进制文件(48 MB)读取,然后将数据传递给名为像素的自定义结构矩阵:
struct pixel {
int r;
int g;
int b;
};
Run Code Online (Sandbox Code Playgroud)
打开文件:
ifstream myFile(inputPath, ios::binary);
pixel **matrixPixel;
Run Code Online (Sandbox Code Playgroud)
以这种方式读取文件:
int position = 0;
for (int i = 0; i < HEIGHT; ++i) {
for (int j = 0; j < WIDTH; ++j) {
if (!myFile.eof()) {
myFile.seekg(position, ios::beg);
myFile.read((char *) &matrixPixel[i][j].r, 1); // red byte
myFile.seekg(position + HEIGHT * WIDTH, ios::beg);
myFile.read((char *) &matrixPixel[i][j].g, 1); // green byte
myFile.seekg(position + HEIGHT * WIDTH * 2, ios::beg);
myFile.read((char *) &matrixPixel[i][j].b, 1); …
Run Code Online (Sandbox Code Playgroud) javascript ×2
c++ ×1
common-lisp ×1
ecmascript-6 ×1
express ×1
fetch ×1
file ×1
filepath ×1
io ×1
lisp ×1
node.js ×1
optimization ×1
performance ×1
reactjs ×1