當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript effects.cancel函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。