async/async.js
function AsyncObservable(fn, context, initialValue) {
	this.resolve = this.resolve.bind(this);
	this.lastSetValue = new SimpleObservable(initialValue);
	this.handler = this.handler.bind(this);

	function observe() {
		this.resolveCalled = false;

		// set inGetter flag to avoid calling `resolve` redundantly if it is called
		// synchronously in the getter
		this.inGetter = true;
		var newVal = fn.call(
			context,
			this.lastSetValue.get(),
			this.bound === true ? this.resolve : undefined
		);
		this.inGetter = false;

		// if the getter returned a value, resolve with the value
		if (newVal !== undefined) {
			this.resolve(newVal);
		}
		// otherwise, if `resolve` was called synchronously in the getter,
		// resolve with the value passed to `resolve`
		else if (this.resolveCalled) {
			this.resolve(this._value);
		}

		// if bound, the handlers will be called by `resolve`
		// returning here would cause a duplicate event
		if (this.bound !== true) {
			return newVal;
		}
	}

	//!steal-remove-start
	if (process.env.NODE_ENV !== 'production') {
		canReflect.assignSymbols(this, {
			"can.getName": function() {
				return (
					canReflect.getName(this.constructor) +
					"<" +
					canReflect.getName(fn) +
					">"
				);
			}
		});
		Object.defineProperty(this.handler, "name", {
			value: canReflect.getName(this) + ".handler"
		});
		Object.defineProperty(observe, "name", {
			value: canReflect.getName(fn) + "::" + canReflect.getName(this.constructor)
		});
	}
	//!steal-remove-end

	this.observation = new Observation(observe, this);
}
function AsyncObservable(fn, context, initialValue) {
	this.resolve = this.resolve.bind(this);
	this.lastSetValue = new SimpleObservable(initialValue);
	this.handler = this.handler.bind(this);

	function observe() {
		this.resolveCalled = false;

		// set inGetter flag to avoid calling `resolve` redundantly if it is called
		// synchronously in the getter
		this.inGetter = true;
		var newVal = fn.call(
			context,
			this.lastSetValue.get(),
			this.bound === true ? this.resolve : undefined
		);
		this.inGetter = false;

		// if the getter returned a value, resolve with the value
		if (newVal !== undefined) {
			this.resolve(newVal);
		}
		// otherwise, if `resolve` was called synchronously in the getter,
		// resolve with the value passed to `resolve`
		else if (this.resolveCalled) {
			this.resolve(this._value);
		}

		// if bound, the handlers will be called by `resolve`
		// returning here would cause a duplicate event
		if (this.bound !== true) {
			return newVal;
		}
	}

	//!steal-remove-start
	if (process.env.NODE_ENV !== 'production') {
		canReflect.assignSymbols(this, {
			"can.getName": function() {
				return (
					canReflect.getName(this.constructor) +
					"<" +
					canReflect.getName(fn) +
					">"
				);
			}
		});
		Object.defineProperty(this.handler, "name", {
			value: canReflect.getName(this) + ".handler"
		});
		Object.defineProperty(observe, "name", {
			value: canReflect.getName(fn) + "::" + canReflect.getName(this.constructor)
		});
	}
	//!steal-remove-end

	this.observation = new Observation(observe, this);
}
function AsyncObservable ( fn , context , initialValue ) { this . resolve = this . resolve . bind ( this ) ; this . lastSetValue = new SimpleObservable ( initialValue ) ; this . handler = this . handler . bind ( this ) ; function observe ( ) { this . resolveCalled = false ; // set inGetter flag to avoid calling `resolve` redundantly if it is called // synchronously in the getter this . inGetter = true ; var newVal = fn . call ( context , this . lastSetValue . get ( ) , this . bound === true ? this . resolve : undefined ) ; this . inGetter = false ; // if the getter returned a value, resolve with the value if ( newVal !== undefined ) { this . resolve ( newVal ) ; } // otherwise, if `resolve` was called synchronously in the getter, // resolve with the value passed to `resolve` else if ( this . resolveCalled ) { this . resolve ( this . _value ) ; } // if bound, the handlers will be called by `resolve` // returning here would cause a duplicate event if ( this . bound !== true ) { return newVal ; } } //!steal-remove-start if ( process . env . NODE_ENV !== 'production' ) { canReflect . assignSymbols ( this , { "can.getName" : function ( ) { return ( canReflect . getName ( this . constructor ) + "<" + canReflect . getName ( fn ) + ">" ) ; } } ) ; Object . defineProperty ( this . handler , "name" , { value : canReflect . getName ( this ) + ".handler" } ) ; Object . defineProperty ( observe , "name" , { value : canReflect . getName ( fn ) + "::" + canReflect . getName ( this . constructor ) } ) ; } //!steal-remove-end this . observation = new Observation ( observe , this ) ; }
This is an observable that is like `settable`, but passed a `resolve` function that can resolve the value of this observable late.
This is an observable that is like settable but passed a resolve function that can resolve the value of this observable late .