我想使用RXJS Observable。基本上它工作正常,但我不仅需要在 observer.next()时做出反应,而且还需要在调用 observer.complete()时做出反应。 如何获得RXJS Observable的OnComplete事件?在我看来,RXJS文档令人困惑。
void TextRenderer::SetupGlyphs(std::string fontPath, int size){
if(shadersInitialized == 0)
CreateShader();
glUseProgram(this->shader);
// FreeType
FT_Library ft;
if (FT_Init_FreeType(&ft))
__android_log_print(ANDROID_LOG_INFO, "SetupGlyphs", "ERROR::FREETYPE: Could not init FreeType Library.");
FT_Face face;
if (FT_New_Face(ft, fontPath.c_str(), 0, &face))
__android_log_print(ANDROID_LOG_INFO, "SetupGlyphs", "ERROR::FREETYPE: Failed to load font: %s", fontPath.c_str());
FT_Set_Pixel_Sizes(face, 0, size);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
for (GLubyte c = 0; c < 128; c++){
if(FT_Load_Char(face, c, FT_LOAD_RENDER)){
printf("ERROR::FREETYPE: Failed to load Glyph\n");
continue;
}
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
face->glyph->bitmap.width,
face->glyph->bitmap.rows,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
face->glyph->bitmap.buffer
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Character character = {
texture,
ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
static_cast<GLuint>(face->glyph->advance.x)
};
characters.insert(std::pair<GLchar, Character>(c, character));
}
glBindTexture(GL_TEXTURE_2D, 0);
FT_Done_Face(face);
FT_Done_FreeType(ft);
}
答案 0 :(得分:16)
subscribe方法接受三个回调。最后一个是完整的事件。
doSome() {
this.service.myMethod()
.subscribe((num:any) => {
console.log(num);
}, (err) => {
this.handleError(err);
}, () => { // <----
this.handleComplete();
});
}
您也可以利用finally
运算符。
doSome() {
this.service.myMethod()
.catch(this.handleError)
.finally(this.handleComplete) // <----
.subscribe((num:any) => {
console.log(num);
});
}
注意:强>
如果我们有错误,这两个例子之间有区别:
如果我们要添加console.log
s,我们会在第一种情况下看到
仅打印handleError
-> handleError
在第二种情况下
-> handleError
-> finally
换句话说,finally
总是被调用,complete
不是。
答案 1 :(得分:0)