All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdeferred.impl.PipedPromise Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
/*
 * Copyright 2013 Ray Tsang
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdeferred.impl;

import org.jdeferred.Deferred;
import org.jdeferred.DoneCallback;
import org.jdeferred.DonePipe;
import org.jdeferred.FailCallback;
import org.jdeferred.FailPipe;
import org.jdeferred.ProgressCallback;
import org.jdeferred.ProgressPipe;
import org.jdeferred.Promise;

public class PipedPromise extends DeferredObject implements Promise{
	public PipedPromise(final Promise promise, final DonePipe doneFilter, final FailPipe failFilter, final ProgressPipe progressFilter) {
		promise.done(new DoneCallback() {
			@SuppressWarnings("unchecked")
			@Override
			public void onDone(D result) {
				if (doneFilter != null) pipe(doneFilter.pipeDone(result));
				else PipedPromise.this.resolve((D_OUT) result);
				
			}
		}).fail(new FailCallback() {
			@SuppressWarnings("unchecked")
			@Override
			public void onFail(F result) {
				if (failFilter != null)  pipe(failFilter.pipeFail(result));
				else PipedPromise.this.reject((F_OUT) result);
			}
		}).progress(new ProgressCallback

() { @SuppressWarnings("unchecked") @Override public void onProgress(P progress) { if (progressFilter != null) pipe(progressFilter.pipeProgress(progress)); else PipedPromise.this.notify((P_OUT) progress); } }); } protected Promise pipe(Promise promise) { promise.done(new DoneCallback() { @Override public void onDone(D_OUT result) { PipedPromise.this.resolve(result); } }).fail(new FailCallback() { @Override public void onFail(F_OUT result) { PipedPromise.this.reject(result); } }).progress(new ProgressCallback() { @Override public void onProgress(P_OUT progress) { PipedPromise.this.notify(progress); } }); return promise; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy