本文整理汇总了TypeScript中rxjs.Observable.timer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.timer方法的具体用法?TypeScript Observable.timer怎么用?TypeScript Observable.timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Observable
的用法示例。
在下文中一共展示了Observable.timer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: callback
return source.retryWhen(errors => {
return Observable
.zip(Observable.range(1, backoffRetries), errors, (i, e) => [i, e])
.do(data => callback(data[1]))
.flatMap(data => Observable.timer(data[0] * data[0] * backoffInterval))
.concat(Observable
.timer(pollingInterval, pollingInterval)
.zip(errors, (timer, error) => error)
.do(error => callback(error)));
});
示例2: checkPanel
function checkPanel(): any {
const panels = atom.workspace.getModalPanels();
if (panels.length) {
const panelItem: GenericSelectListView = panels[0].item;
expect(panelItem._items.length).to.be.eql(2);
panelItem.onConfirm(panelItem._items[0].name);
return p;
} else {
return Observable.timer(100).toPromise()
.then(() => checkPanel());
}
}
示例3: factory
function createObservable<T>(factory: () => Promise<T>): Observable<T> {
const topic: Promise<T> = factory();
if (topic instanceof Promise) {
const lazyRec: () => Observable<T> = () => {
return Observable.fromPromise(factory()).concat(
Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
};
return Observable.fromPromise(topic).concat(
Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
} else {
return Observable.fromPromise(topic);
}
}
示例4: Promise
return new Promise(async resolve => {
await Observable.timer(1000).toPromise();
let a = document.createElement('a');
let blob = this.newBlob(ew, 'text/plain;charset=utf-8');
let url = window.URL.createObjectURL(blob);
document.body.appendChild(a);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
return resolve();
});
示例5: constructor
constructor(private http: Http, private randomMessage: RandomMessage) {
this.messages$ = new Subject<Message>();
Observable.timer(0, 3000)
// .take(5)
.delayWhen(_ => Observable.interval(Math.random() * 10000))
.switchMap(_ => {
return this.http.get('https://randomuser.me/api/')
})
.map(resp => resp.json())
.subscribe((data: any) => {
const user = data.results[0];
this.messages$.next({
id: Date.now(),
name: namenize(user.name.first),
image: user.picture.thumbnail,
message: this.randomMessage.get()
});
}, error => {
console.error(error);
});
}
示例6: watchForAutoLogin
watchForAutoLogin(): Observable<ILoginActionPayload> {
const isAuto = ( loginState: ILoginState ): boolean => {
if (loginState)
return loginState.userId === null;
return false;
};
let meteorUser = Meteor.user();
let lastLoginState = null;
ReduxPackageCombiner
.select(LOGIN_PACKAGE_NAME)
.subscribe((loginState: ILoginState) => {
lastLoginState = loginState;
});
if (meteorUser) {
return Observable.of(LoginActions.loginSuccessFactory(
this.userFromMeteorUser(meteorUser),
meteorUser._id,
isAuto(lastLoginState)
));
}
let subject = new Subject();
let timer = Observable.timer(500, 1000);
let subscription = timer.subscribe(() => {
let meteorUser = Meteor.user();
if (meteorUser) {
subject.next( LoginActions.loginSuccessFactory(
this.userFromMeteorUser(meteorUser),
meteorUser._id,
isAuto(lastLoginState)
));
subject.complete();
subscription.unsubscribe();
}
});
return subject;
};
示例7: run
export function run() {
const stream = Observable.timer(1000,1000);
stream.subscribe(value => console.log(value));
}
示例8:
.debounce((x) => {
return Rx.Observable.timer(500);
})
示例9: lazyRec
const lazyRec: () => Observable<T> = () => {
return Observable.fromPromise(factory()).concat(
Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
};
示例10: createScheduler
public static createScheduler(pollSchedule = SETTINGS.pollSchedule): IScheduler {
let scheduler = new Subject();
let lastRunTimestamp = new Date().getTime();
let pendingRun: IPromise<void> = null;
let suspended = false;
// When creating the timer, use last run as the dueTime (first arg); zero can lead to concurrency issues
// where the scheduler will fire shortly after being subscribed to, resulting in surprising immediate refreshes
let source = Observable.timer(pollSchedule, pollSchedule);
const run = (): void => {
if (suspended) {
return;
}
$timeout.cancel(pendingRun);
lastRunTimestamp = new Date().getTime();
scheduler.next(true);
pendingRun = null;
};
source.subscribe(run);
const suspendScheduler = (): void => {
$log.debug('auto refresh suspended');
suspended = true;
};
const scheduleNextRun = (delay: number) => {
// do not schedule another run if a run is pending
suspended = false;
pendingRun = pendingRun || $timeout(run, delay);
};
const resumeScheduler = (): void => {
suspended = false;
const now = new Date().getTime();
$log.debug('auto refresh resumed');
if (now - lastRunTimestamp > pollSchedule) {
run();
} else {
scheduleNextRun(pollSchedule - (now - lastRunTimestamp));
}
};
const watchDocumentVisibility = (): void => {
$log.debug('document visibilityState changed to: ', document.visibilityState);
if (document.visibilityState === 'visible') {
resumeScheduler();
} else {
suspendScheduler();
}
};
const scheduleImmediate = (): void => {
run();
suspended = true;
scheduleNextRun(pollSchedule);
};
document.addEventListener('visibilitychange', watchDocumentVisibility);
$window.addEventListener('offline', suspendScheduler);
$window.addEventListener('online', resumeScheduler);
scheduler.next(true);
return {
subscribe: scheduler.subscribe.bind(scheduler),
scheduleImmediate,
unsubscribe: () => {
suspended = true;
if (scheduler) {
scheduler.next(false);
scheduler.unsubscribe();
}
scheduler = null;
source = null;
$timeout.cancel(pendingRun);
document.removeEventListener('visibilitychange', watchDocumentVisibility);
$window.removeEventListener('offline', suspendScheduler);
$window.removeEventListener('online', resumeScheduler);
},
};
}