Tribe__Promise::then( callable|Tribe__Utils__Callback $resolved, callable|Tribe__Utils__Callback $rejected = null, array $resolved_args = null, array $rejected_args = null )

Sets a callback, and optional arguments, that will be called when the promise is resolved.

The callback and arguments must be serializable and make sense in the context of, potentially, a different call from the one where this method is called.


Parameters

$resolved

(callable|Tribe__Utils__Callback) (Required) The callback to call on success.

$rejected

(callable|Tribe__Utils__Callback) (Optional) The callback to call on failure.

Default value: null

$resolved_args

(array) (Optional) The arguments that will be passed to the resolved callback.

Default value: null

$rejected_args

(array) (Optional) The arguments that will be passed to the rejected callback.

Default value: null


Top ↑

Return

(Tribe__Promise) This promise.


Top ↑

Source

File: src/Tribe/Promise.php

	public function then( $resolved, $rejected = null, array $resolved_args = null, array $rejected_args = null ) {
		if ( $this->did_save ) {
			throw new LogicException( 'The promise "then" method should be called before the "save" one' );
		}

		$this->resolved      = $resolved;
		$this->resolved_args = $resolved_args;
		$this->rejected      = $rejected;
		$this->rejected_args = $rejected_args;

		foreach ( $this->data as &$item ) {
			$item['resolved']      = $this->resolved;
			$item['resolved_args'] = $this->resolved_args;
			$item['rejected']      = $this->rejected;
			$item['rejected_args'] = $this->rejected_args;
		}

		return $this;
	}

Top ↑

Changelog

Changelog
Version Description
4.9.5 Introduced.