How to use p-defer - 6 common examples

To help you get started, we’ve selected a few p-defer 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 zeebe-io / zeebe-modeler / client / src / app / __tests__ / AppSpec.js View on Github external
it('works', async function() {

        // given
        const deferred = pDefer();

        function onError(error) {
          deferred.resolve(error);
        }

        const {
          app
        } = createApp({ onError }, mount);

        await app.createDiagram();

        const tabInstance = app.tabRef.current;

        const error = new Error('YZO!');

        // when
github unboundedsystems / adapt / cli / src / ui / dynamic_task_mgr.ts View on Github external
if (!Number.isInteger(runOnChildTask) || runOnChildTask < 1) {
        throw new Error(`createTask: runOnChildTask must be an integer >= 1`);
    }
    const tStatus = registry.get(id);

    if (tStatus) {
        if (!tStatus.adoptable) throw new Error(`Task ${id} has already been created`);
        return;
    } else {
        const newStatus = {
            id,
            event: TaskState.Created,
            status: undefined,
            adoptable,
            dPromise: pDefer(),
            settled: false,
            childTasksNeeded: runOnChildTask,
            trivial,
        };

        // Record when the promise has been settled
        const settled = () => newStatus.settled = true;
        newStatus.dPromise.promise.then(settled, settled);

        registry.set(id, newStatus);
    }

    if (trivial && !debugTrivial.enabled) return;

    const returnHolder: Holder = {};
github zeebe-io / zeebe-modeler / client / src / app / App.js View on Github external
constructor(props) {
    super(props);

    this.state = {
      ...INITIAL_STATE,
      tabShown: pDefer()
    };

    this.tabComponentCache = {};

    // TODO(nikku): make state
    this.navigationHistory = new History();

    this.events = new EventEmitter();

    // TODO(nikku): make state
    this.closedTabs = new History();

    this.tabRef = React.createRef();

    const userPlugins = this.getPlugins('client');
github unboundedsystems / adapt / testutils / src / minikube-mocha.ts View on Github external
private async getInfo() {
        if (this.info_) return this.info_;

        const deferred = pDefer();
        this.waiters.push(deferred);

        if (this.waiters.length === 1) {
            return startTestMinikube().then((mkinfo) => {
                this.info_ = mkinfo;
                while (true) {
                    const waiter = this.waiters.pop();
                    if (!waiter) break;
                    waiter.resolve(this.info_);
                }
                return this.info_;
            });
        }
        return deferred.promise;
    }
github unboundedsystems / adapt / core / src / server / server_base.ts View on Github external
return new Promise((resolve, reject) => {
            const releaseComplete = pDefer();

            this.locks.acquire("thelock",
                (releaseLock) => {
                    resolve({
                        release: async () => {
                            releaseLock();
                            return releaseComplete.promise;
                        },
                        [$serverLock]: true,
                    });
                },
                (err) => {
                    if (err) {
                        reject(err);
                        releaseComplete.reject(err);
                    } else {
github zeebe-io / zeebe-modeler / client / src / app / App.js View on Github external
tabShown
    } = this.state;

    if (activeTab === tab) {
      return tabShown.promise;
    }

    if (!this.isEmptyTab(tab)) {
      const navigationHistory = this.navigationHistory;

      if (navigationHistory.get() !== tab) {
        navigationHistory.push(tab);
      }
    }

    const deferred = pDefer();

    this.setState({
      activeTab: tab,
      Tab: this.getTabComponent(tab),
      tabShown: deferred,
      tabState: {},
      tabLoadingState: 'loading'
    });

    return deferred.promise;
  }

p-defer

Create a deferred promise

MIT
Latest version published 17 days ago

Package Health Score

83 / 100
Full package analysis

Popular p-defer functions