我有一个轮询用例,其中:
这就是我目前的实现方式:
this.trackSpoke$ = interval(5000)
.pipe(
timeout(250000),
startWith(0),
switchMap(() =>
this.sharedService.pollForAPropertyValue(
"newuser"
)
)
)
.subscribe(
(data: SpokeProperty) => {
this.CheckSpokeStatus(data);
},
error => {
this.trackSpoke$.unsubscribe();
this.createSpokeState.CdhResponseTimedOut();
}
);
private CheckSpokeStatus(data) {
if (data.PropertyValue === "5") {
this.trackSpoke$.unsubscribe();
//display success
} else {
//keep the polling going
}
}
Run Code Online (Sandbox Code Playgroud)
但是,上述实现并没有超时。
需要做什么才能让它超时并且我能够实现所有提到的用例?
我有以下senario:
用户可以登录网站。用户可以添加/删除民意调查(一个有两个选项的问题)。通过选择任何选项,任何用户都可以对民意调查发表意见。
考虑到上述情况,我有三种模型- Users Polls Options。它们如下-
var usersSchema = new Schema({
username : {
type : String,
required : true
},
email : {
type : String,
required : true,
unique : true
},
password : String,
polls : [pollSchema]
Run Code Online (Sandbox Code Playgroud)
});
var pollSchema = new Schema({
question : {
type : String,
required : true
},
options : [optionSchema]
Run Code Online (Sandbox Code Playgroud)
});
var optionSchema = new Schema({
optionName : {
type : String,
required : true,
},
optionCount : {
type …Run Code Online (Sandbox Code Playgroud)