本文整理汇总了TypeScript中redux-saga/effects.cancel函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cancel函数的具体用法?TypeScript cancel怎么用?TypeScript cancel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cancel函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: countdownFlow
function* countdownFlow() {
const tasks: StringKeyValuePair = {};
while (true) {
const action = yield take([
actions.pause,
actions.remove,
actions.reset,
actions.start,
actions.stop,
]);
const countdownId = action.payload;
if (hasSameActionType(action, actions.pause)) {
yield cancel(tasks[countdownId]);
const countdown: Countdown = yield select(({ countdowns }: State) =>
countdowns.find((c: Countdown) => c.id === countdownId),
);
yield put(actions.update(countdownId, {
paused: true,
alarmSoundEnabled: countdown.milliseconds === 0,
}));
}
if (hasSameActionType(action, actions.remove)) {
if (tasks[countdownId]) {
yield cancel(tasks[countdownId]);
}
}
if (hasSameActionType(action, actions.reset)) {
yield cancel(tasks[countdownId]);
const countdown: Countdown = yield select(({ countdowns }: State) =>
countdowns.find((c: Countdown) => c.id === countdownId),
);
if (!countdown.paused) {
tasks[countdownId] = yield fork(countdownInterval, countdownId);
}
}
if (hasSameActionType(action, actions.start)) {
tasks[countdownId] = yield fork(countdownInterval, countdownId);
}
if (hasSameActionType(action, actions.stop)) {
yield put(actions.update(countdownId, { alarmSoundEnabled: false }));
}
}
}
开发者ID:danilobjr,项目名称:PomodoroTimer,代码行数:54,代码来源:countdowns.ts
示例2: fork
yield fork(function*() {
let connectingChan;
while(1) {
yield take([OPENING_TANDEM_APP, TANDEM_FE_CONNECTIVITY]);
const state: ExtensionState = yield select();
if (connectingChan) {
yield cancel(connectingChan);
connectingChan = undefined;
}
if (state.tandemEditorStatus === TandemEditorReadyStatus.CONNECTED) {
status.text = "$(zap) Tandem";
status.tooltip = "Connected to Tandem";
} else if (state.tandemEditorStatus === TandemEditorReadyStatus.CONNECTING) {
status.tooltip = "Connecting to Tandem";
connectingChan = yield spawn(function*() {
while(1) {
// https://github.com/sindresorhus/elegant-spinner/blob/master/index.js
status.text = SPIN_SEQ.charAt(i = (i + 1) % SPIN_SEQ.length) + " Tandem";
yield call(delay, 100);
}
});
} else if (state.tandemEditorStatus === TandemEditorReadyStatus.DISCONNECTED) {
status.text = "âś Tandem";
status.tooltip = "Disconnected from Tandem";
}
status.show();
}
});
开发者ID:cryptobuks,项目名称:tandem,代码行数:31,代码来源:vscode.ts
示例3: githubData
export function* githubData(): IterableIterator<any> { // TODO: fix return value
// Fork watcher so we can continue execution
const watcher = yield fork(getReposWatcher);
// Suspend execution until location changes
yield take(LOCATION_CHANGE);
yield cancel(watcher);
}
开发者ID:StrikeForceZero,项目名称:react-boilerplate,代码行数:8,代码来源:sagas.ts
示例4: beginPollingSymbols
function* beginPollingSymbols(action: Action<string>) {
try {
const pollingTaskId = yield fork(pollingSaga, action);
yield take([String(loadStructureSuccess), String(loadStructureFailed)]);
yield cancel(pollingTaskId);
} catch (err) {
yield put(loadStructureFailed(err));
}
}
开发者ID:elastic,项目名称:kibana,代码行数:9,代码来源:structure.ts
示例5: main
function* main() {
while( yield take('START_BACKGROUND_SYNC') ) {
// starts the task in the background
const bgSyncTask = yield fork(bgSync)
// wait for the user stop action
yield take('STOP_BACKGROUND_SYNC')
// user clicked stop. cancel the background task
// this will throw a SagaCancellationException into the forked bgSync
// task
yield cancel(bgSyncTask)
}
}
开发者ID:HawkHouseIntegration,项目名称:DefinitelyTyped,代码行数:13,代码来源:redux-saga-tests.ts
示例6: parseRepoUri
return function*(action: Action<any>) {
const repoUri = parseRepoUri(action);
// Cancel existing runner to deduplicate the polling
yield put(pollingStopActionFunction(repoUri));
// Make a fork to run the repo index status polling
const task = yield fork(pollStatusRun, repoUri);
// Wait for the cancellation task
yield take(pollingStopActionFunctionPattern(repoUri));
// Cancell the task
yield cancel(task);
};
开发者ID:elastic,项目名称:kibana,代码行数:15,代码来源:project_status.ts
示例7: testCancel
function* testCancel(): SagaIterator {
yield cancel()
// typings:expect-error
yield cancel(undefined)
// typings:expect-error
yield cancel({})
yield cancel(task)
// typings:expect-error
yield cancel(task, task)
yield cancel([task, task])
yield cancel([task, task, task])
const tasks: Task[] = []
yield cancel(tasks)
// typings:expect-error
yield cancel([task, task, {}])
}
开发者ID:rahulrcopart,项目名称:redux-saga,代码行数:21,代码来源:effects.ts
示例8: testCancel
function* testCancel(): SagaIterator {
yield cancel();
// typings:expect-error
yield cancel(undefined);
// typings:expect-error
yield cancel({});
yield cancel(task);
yield cancel(task, task);
yield cancel(task, task, task);
const tasks: Task[] = [];
yield cancel(...tasks);
// typings:expect-error
yield cancel(task, task, {});
}
开发者ID:javarouka,项目名称:redux-saga,代码行数:19,代码来源:effects.ts
示例9: chronometerFlow
function* chronometerFlow() {
let task = null;
while (true) {
const action: Action<void> = yield take([
actions.start,
actions.stop,
]);
if (hasSameActionType(action, actions.start)) {
task = yield fork(chronometerInterval);
}
if (hasSameActionType(action, actions.stop)) {
yield cancel(task);
}
}
}
开发者ID:danilobjr,项目名称:PomodoroTimer,代码行数:18,代码来源:chronometer.ts
示例10: handleWatchUrisRequest
function* handleWatchUrisRequest() {
yield take(INIT_SERVER_REQUESTED);
let child;
let chan;
let prevWatchUris = [];
while(true) {
const state: ApplicationState = yield select();
const { watchUris = [], fileCache } = state;
const diffs = diffArray(watchUris, prevWatchUris, (a, b) => a === b ? 0 : -1);
const updates = diffs.mutations.filter(mutation => mutation.type === ARRAY_UPDATE);
if (prevWatchUris.length && updates.length === diffs.mutations.length) {
console.log("no change");
continue;
}
prevWatchUris = watchUris;
const componentFileTester = getModulesFileTester(state);
// remove file path and ensure that it doesn't exist in component pattern.
const urisByFilePath = watchUris.filter(((uri) => uri.substr(0, 5) === "file:")).map((uri) => (
uri.replace("file://", "")
)).filter(filePath => !componentFileTester(filePath));
const allUris = [
getModulesFilePattern(state),
...urisByFilePath
];
console.log("watching: ", allUris);
if (child) {
chan.close();
cancel(child);
}
const readFile = filePath => {
return ({
filePath: filePath,
a: Math.random(),
content: new Buffer(fs.readFileSync(filePath, "utf8")),
mtime: fs.lstatSync(filePath).mtime
});
};
const initialFileCache = glob.sync(getModulesFilePattern(state)).map((filePath) => (
fileCache.find((item) => item.filePath === filePath) || readFile(filePath)
));
chan = yield eventChannel((emit) => {
const watcher = chokidar.watch(allUris);
watcher.on("ready", () => {
const emitChange = (path) => {
const mtime = fs.lstatSync(path).mtime;
const fileCacheItem = initialFileCache.find((item) => item.filePath === path);
if (fileCacheItem && fileCacheItem.mtime === mtime) {
return;
}
const newContent = fs.readFileSync(path, "utf8");
const publicPath = getPublicFilePath(path, state);
// for internal -- do not want this being sent over the network since it is slow
emit(fileContentChanged(path, publicPath, newContent, mtime));
}
watcher.on("add", emitChange);
watcher.on("change", emitChange);
watcher.on("unlink", (path) => {
emit(fileRemoved(path, getPublicFilePath(path, state)));
});
});
return () => {
watcher.close();
};
});
const filesByUri = fileCache.map((item) => item.filePath);
yield put(watchingFiles(initialFileCache));
child = yield spawn(function*() {
while(1) {
const c = yield take(chan);
try {
yield put(c);
} catch(e) {
console.warn("warn ", e);
}
}
});
yield take(WATCH_URIS_REQUESTED);
//.........这里部分代码省略.........
开发者ID:cryptobuks,项目名称:tandem,代码行数:101,代码来源:uri-watcher.ts
注:本文中的redux-saga/effects.cancel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论