How to use scheduler - 10 common examples

To help you get started, we’ve selected a few scheduler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / react / packages / react-test-renderer / src / ReactTestRendererAct.js View on Github external
import {
  batchedUpdates,
  flushPassiveEffects,
  IsThisRendererActing,
} from 'react-reconciler/inline.test';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
import * as Scheduler from 'scheduler';

const {IsSomeRendererActing} = ReactSharedInternals;

// this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

const isSchedulerMocked =
  typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';
const flushWork =
  Scheduler.unstable_flushAllWithoutAsserting ||
  function() {
    let didFlushWork = false;
    while (flushPassiveEffects()) {
      didFlushWork = true;
    }

    return didFlushWork;
  };

function flushWorkAndMicroTasks(onDone: (err: ?Error) => void) {
  try {
    flushWork();
    enqueueTask(() => {
      if (flushWork()) {
github makuga01 / dnsFookup / FE / node_modules / react-dom / cjs / react-dom-test-utils.development.js View on Github external
eventNameDispatchConfigs = _ReactDOM$__SECRET_IN[4],
    accumulateTwoPhaseDispatches = _ReactDOM$__SECRET_IN[5],
    accumulateDirectDispatches = _ReactDOM$__SECRET_IN[6],
    enqueueStateRestore = _ReactDOM$__SECRET_IN[7],
    restoreStateIfNeeded = _ReactDOM$__SECRET_IN[8],
    dispatchEvent = _ReactDOM$__SECRET_IN[9],
    runEventsInBatch = _ReactDOM$__SECRET_IN[10],

/* eslint-enable no-unused-vars */
flushPassiveEffects = _ReactDOM$__SECRET_IN[11],
    IsThisRendererActing = _ReactDOM$__SECRET_IN[12];
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

var isSchedulerMocked = typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';

var flushWork = Scheduler.unstable_flushAllWithoutAsserting || function () {
  var didFlushWork = false;

  while (flushPassiveEffects()) {
    didFlushWork = true;
  }

  return didFlushWork;
};

function flushWorkAndMicroTasks(onDone) {
  try {
    flushWork();
    enqueueTask(function () {
      if (flushWork()) {
github makuga01 / dnsFookup / FE / node_modules / react-dom / cjs / react-dom-test-utils.development.js View on Github external
accumulateDirectDispatches = _ReactDOM$__SECRET_IN[6],
    enqueueStateRestore = _ReactDOM$__SECRET_IN[7],
    restoreStateIfNeeded = _ReactDOM$__SECRET_IN[8],
    dispatchEvent = _ReactDOM$__SECRET_IN[9],
    runEventsInBatch = _ReactDOM$__SECRET_IN[10],

/* eslint-enable no-unused-vars */
flushPassiveEffects = _ReactDOM$__SECRET_IN[11],
    IsThisRendererActing = _ReactDOM$__SECRET_IN[12];
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

var isSchedulerMocked = typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';

var flushWork = Scheduler.unstable_flushAllWithoutAsserting || function () {
  var didFlushWork = false;

  while (flushPassiveEffects()) {
    didFlushWork = true;
  }

  return didFlushWork;
};

function flushWorkAndMicroTasks(onDone) {
  try {
    flushWork();
    enqueueTask(function () {
      if (flushWork()) {
        flushWorkAndMicroTasks(onDone);
      } else {
github facebook / react / packages / react-dom / src / test-utils / ReactTestUtilsAct.js View on Github external
dispatchEvent,
  runEventsInBatch,
  /* eslint-enable no-unused-vars */
  flushPassiveEffects,
  IsThisRendererActing,
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;

const batchedUpdates = ReactDOM.unstable_batchedUpdates;

const {IsSomeRendererActing} = ReactSharedInternals;

// this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

const isSchedulerMocked =
  typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';
const flushWork =
  Scheduler.unstable_flushAllWithoutAsserting ||
  function() {
    let didFlushWork = false;
    while (flushPassiveEffects()) {
      didFlushWork = true;
    }

    return didFlushWork;
  };

function flushWorkAndMicroTasks(onDone: (err: ?Error) => void) {
  try {
    flushWork();
    enqueueTask(() => {
      if (flushWork()) {
github facebook / react / packages / react-test-renderer / src / ReactTestRendererAct.js View on Github external
flushPassiveEffects,
  IsThisRendererActing,
} from 'react-reconciler/inline.test';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
import * as Scheduler from 'scheduler';

const {IsSomeRendererActing} = ReactSharedInternals;

// this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

const isSchedulerMocked =
  typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';
const flushWork =
  Scheduler.unstable_flushAllWithoutAsserting ||
  function() {
    let didFlushWork = false;
    while (flushPassiveEffects()) {
      didFlushWork = true;
    }

    return didFlushWork;
  };

function flushWorkAndMicroTasks(onDone: (err: ?Error) => void) {
  try {
    flushWork();
    enqueueTask(() => {
      if (flushWork()) {
        flushWorkAndMicroTasks(onDone);
      } else {
github polakowo / datadocs / website / node_modules / react-dom / cjs / react-dom-test-utils.development.js View on Github external
var eventNameDispatchConfigs$1 = _ReactDOM$__SECRET_IN$1[4];
var accumulateTwoPhaseDispatches$1 = _ReactDOM$__SECRET_IN$1[5];
var accumulateDirectDispatches$1 = _ReactDOM$__SECRET_IN$1[6];
var enqueueStateRestore$1 = _ReactDOM$__SECRET_IN$1[7];
var restoreStateIfNeeded$1 = _ReactDOM$__SECRET_IN$1[8];
var dispatchEvent$1 = _ReactDOM$__SECRET_IN$1[9];
var runEventsInBatch$1 = _ReactDOM$__SECRET_IN$1[10];
var flushPassiveEffects$1 = _ReactDOM$__SECRET_IN$1[11];
var IsThisRendererActing$1 = _ReactDOM$__SECRET_IN$1[12];
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

var isSchedulerMocked = typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';

var flushWork = Scheduler.unstable_flushAllWithoutAsserting || function () {
  var didFlushWork = false;

  while (flushPassiveEffects$1()) {
    didFlushWork = true;
  }

  return didFlushWork;
};

function flushWorkAndMicroTasks(onDone) {
  try {
    flushWork();
    enqueueTask$1(function () {
      if (flushWork()) {
        flushWorkAndMicroTasks(onDone);
      } else {
github facebook / react / packages / react-dom / src / test-utils / ReactTestUtilsAct.js View on Github external
/* eslint-enable no-unused-vars */
  flushPassiveEffects,
  IsThisRendererActing,
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;

const batchedUpdates = ReactDOM.unstable_batchedUpdates;

const {IsSomeRendererActing} = ReactSharedInternals;

// this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

const isSchedulerMocked =
  typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';
const flushWork =
  Scheduler.unstable_flushAllWithoutAsserting ||
  function() {
    let didFlushWork = false;
    while (flushPassiveEffects()) {
      didFlushWork = true;
    }

    return didFlushWork;
  };

function flushWorkAndMicroTasks(onDone: (err: ?Error) => void) {
  try {
    flushWork();
    enqueueTask(() => {
      if (flushWork()) {
        flushWorkAndMicroTasks(onDone);
      } else {
github polakowo / datadocs / website / node_modules / react-dom / cjs / react-dom-test-utils.development.js View on Github external
var getFiberCurrentPropsFromNode$1 = _ReactDOM$__SECRET_IN$1[2];
var injectEventPluginsByName$1 = _ReactDOM$__SECRET_IN$1[3];
var eventNameDispatchConfigs$1 = _ReactDOM$__SECRET_IN$1[4];
var accumulateTwoPhaseDispatches$1 = _ReactDOM$__SECRET_IN$1[5];
var accumulateDirectDispatches$1 = _ReactDOM$__SECRET_IN$1[6];
var enqueueStateRestore$1 = _ReactDOM$__SECRET_IN$1[7];
var restoreStateIfNeeded$1 = _ReactDOM$__SECRET_IN$1[8];
var dispatchEvent$1 = _ReactDOM$__SECRET_IN$1[9];
var runEventsInBatch$1 = _ReactDOM$__SECRET_IN$1[10];
var flushPassiveEffects$1 = _ReactDOM$__SECRET_IN$1[11];
var IsThisRendererActing$1 = _ReactDOM$__SECRET_IN$1[12];
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js

var isSchedulerMocked = typeof Scheduler.unstable_flushAllWithoutAsserting === 'function';

var flushWork = Scheduler.unstable_flushAllWithoutAsserting || function () {
  var didFlushWork = false;

  while (flushPassiveEffects$1()) {
    didFlushWork = true;
  }

  return didFlushWork;
};

function flushWorkAndMicroTasks(onDone) {
  try {
    flushWork();
    enqueueTask$1(function () {
      if (flushWork()) {
github jaredpalmer / formik / packages / formik / src / Formik.tsx View on Github external
(values: Values = state.values) => {
      return unstable_runWithPriority(LowPriority, () => {
        return runAllValidations(values)
        .then(combinedErrors => {
          if (!!isMounted.current) {
            dispatch({ type: 'SET_ERRORS', payload: combinedErrors });
          }
          return combinedErrors;
        })
        .catch(actualException => {
          if (process.env.NODE_ENV !== 'production') {
            // Users can throw during validate, however they have no way of handling their error on touch / blur. In low priority, we need to handle it
            console.warn(
              `Warning: An unhandled error was caught during low priority validation in `,
              actualException
            );
          }
        });
github facebook / react / packages / react-reconciler / src / ReactFiberScheduler.old.js View on Github external
? childExpirationTimeAfterCommit
      : updateExpirationTimeAfterCommit;
  if (earliestRemainingTimeAfterCommit === NoWork) {
    // If there's no remaining work, we can clear the set of already failed
    // error boundaries.
    legacyErrorBoundariesThatAlreadyFailed = null;
  }
  onCommit(root, earliestRemainingTimeAfterCommit);

  if (enableSchedulerTracing) {
    __interactionsRef.current = prevInteractions;

    let subscriber;

    try {
      subscriber = __subscriberRef.current;
      if (subscriber !== null && root.memoizedInteractions.size > 0) {
        const threadID = computeThreadID(
          committedExpirationTime,
          root.interactionThreadID,
        );
        subscriber.onWorkStopped(root.memoizedInteractions, threadID);
      }
    } catch (error) {
      // It's not safe for commitRoot() to throw.
      // Store the error for now and we'll re-throw in finishRendering().
      if (!hasUnhandledError) {
        hasUnhandledError = true;
        unhandledError = error;
      }
    } finally {
      // Clear completed interactions from the pending Map.