本文整理汇总了Java中org.jdeferred.impl.DeferredObject.reject方法的典型用法代码示例。如果您正苦于以下问题:Java DeferredObject.reject方法的具体用法?Java DeferredObject.reject怎么用?Java DeferredObject.reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdeferred.impl.DeferredObject
的用法示例。
在下文中一共展示了DeferredObject.reject方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWorkInBackground
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
private Promise<String, Throwable, Integer> doWorkInBackground() {
final DeferredObject<String, Throwable, Integer> deferredObject = new DeferredObject<String, Throwable, Integer>();
Runnable work = new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i <= 100; i += 20) {
Thread.sleep(1000);
Log.i(TAG, "Done " + i + "% of work on thread " + Thread.currentThread().getId());
deferredObject.notify(i);
}
deferredObject.resolve("Finish!");
} catch (Throwable ex) {
deferredObject.reject(ex);
}
}
};
mDeferredManager.when(work);
return mDeferredManager.when(deferredObject);
}
示例2: readCharacteristic
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
public Promise<BluetoothGattCharacteristic, Integer, Void> readCharacteristic(BluetoothGattCharacteristic characteristic) {
checkConnected();
// If there's already a request in flight, return the current promise for results.
DeferredObject<BluetoothGattCharacteristic, Integer, Void> deferred = readCharacteristic.get(new CharacteristicKey(characteristic));
if (deferred != null && deferred.isPending()) {
return deferred.promise();
}
// Read descriptor and return a promise for the results.
deferred = new DeferredObject<BluetoothGattCharacteristic, Integer, Void>();
if (!gatt.readCharacteristic(characteristic)) {
deferred.reject(null);
}
readCharacteristic.put(new CharacteristicKey(characteristic), deferred);
return deferred.promise();
}
示例3: writeCharacteristic
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
public Promise<BluetoothGattCharacteristic, Integer, Void> writeCharacteristic(BluetoothGattCharacteristic characteristic) {
checkConnected();
// If there's already a request in flight, return the current promise for results.
DeferredObject<BluetoothGattCharacteristic, Integer, Void> deferred = writeCharacteristic.get(new CharacteristicKey(characteristic));
if (deferred != null && deferred.isPending()) {
return deferred.promise();
}
// Read descriptor and return a promise for the results.
deferred = new DeferredObject<BluetoothGattCharacteristic, Integer, Void>();
if (!gatt.writeCharacteristic(characteristic)) {
deferred.reject(null);
}
writeCharacteristic.put(new CharacteristicKey(characteristic), deferred);
return deferred.promise();
}
示例4: readDescriptor
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
public Promise<BluetoothGattDescriptor, Integer, Void> readDescriptor(BluetoothGattDescriptor descriptor) {
checkConnected();
// If there's already a request in flight, return the current promise for results.
DeferredObject<BluetoothGattDescriptor, Integer, Void> deferred = readDescriptor.get(new DescriptorKey(descriptor));
if (deferred != null && deferred.isPending()) {
return deferred.promise();
}
// Read descriptor and return a promise for the results.
deferred = new DeferredObject<BluetoothGattDescriptor, Integer, Void>();
if (!gatt.readDescriptor(descriptor)) {
deferred.reject(null);
}
readDescriptor.put(new DescriptorKey(descriptor), deferred);
return deferred.promise();
}
示例5: writeDescriptor
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
public Promise<BluetoothGattDescriptor, Integer, Void> writeDescriptor(BluetoothGattDescriptor descriptor) {
checkConnected();
// If there's already a request in flight, return the current promise for results.
DeferredObject<BluetoothGattDescriptor, Integer, Void> deferred = writeDescriptor.get(new DescriptorKey(descriptor));
if (deferred != null && deferred.isPending()) {
return deferred.promise();
}
// Write descriptor and return a promise for the results.
deferred = new DeferredObject<BluetoothGattDescriptor, Integer, Void>();
if (!gatt.writeDescriptor(descriptor)) {
deferred.reject(null);
}
writeDescriptor.put(new DescriptorKey(descriptor), deferred);
return deferred.promise();
}
示例6: onCharacteristicRead
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
DeferredObject<BluetoothGattCharacteristic, Integer, Void> deferred = readCharacteristic.get(new CharacteristicKey(characteristic));
if (deferred != null) {
if (status == BluetoothGatt.GATT_SUCCESS) {
deferred.resolve(characteristic);
}
else {
deferred.reject(status);
}
}
}
示例7: onCharacteristicWrite
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
DeferredObject<BluetoothGattCharacteristic, Integer, Void> deferred = writeCharacteristic.get(new CharacteristicKey(characteristic));
if (deferred != null) {
// Resolve or reject the deferred based on success or failure of the characteristic write.
if (status == BluetoothGatt.GATT_SUCCESS) {
deferred.resolve(characteristic);
}
else {
deferred.reject(status);
}
}
}
示例8: onDescriptorRead
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
@Override
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorRead(gatt, descriptor, status);
DeferredObject<BluetoothGattDescriptor, Integer, Void> deferred = readDescriptor.get(new DescriptorKey(descriptor));
if (deferred != null) {
// Resolve or reject the deferred based on success or failure of the descriptor read.
if (status == BluetoothGatt.GATT_SUCCESS) {
deferred.resolve(descriptor);
}
else {
deferred.reject(status);
}
}
}
示例9: onDescriptorWrite
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
DeferredObject<BluetoothGattDescriptor, Integer, Void> deferred = writeDescriptor.get(new DescriptorKey(descriptor));
if (deferred != null) {
// Resolve or reject the deferred based on success or failure of the descriptor write.
if (status == BluetoothGatt.GATT_SUCCESS) {
deferred.resolve(descriptor);
}
else {
deferred.reject(status);
}
}
}
示例10: setCharacteristicNotification
import org.jdeferred.impl.DeferredObject; //导入方法依赖的package包/类
public Promise<Void, Void, BluetoothGattCharacteristic> setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable) {
checkConnected();
DeferredObject<Void, Void, BluetoothGattCharacteristic> deferred = changeCharacteristic.get(new CharacteristicKey(characteristic));
// Handle when enable has already been called.
if (enable && deferred != null && deferred.isPending()) {
// Return the in progress deferred.
return deferred.promise();
}
// Handle disable for an already established notification.
else if (!enable && deferred != null) {
// Finish the current deferred.
deferred.resolve(null);
changeCharacteristic.remove(new CharacteristicKey(characteristic));
// Disable notifications.
deferred = new DeferredObject<Void, Void, BluetoothGattCharacteristic>();
if (!gatt.setCharacteristicNotification(characteristic, false)) {
deferred.reject(null);
}
else {
deferred.resolve(null);
}
// Return a deferred to give success/failure of the disable.
// This deferred is immediately resolved or rejected because there is no async indication
// of the setCharacteristicNotification finishing (only progress updates).
return deferred.promise();
}
// Handle enabling notifications.
else if (enable) {
// Setup and return the deferred for receiving progress of notification changes.
deferred = new DeferredObject<Void, Void, BluetoothGattCharacteristic>();
if (!gatt.setCharacteristicNotification(characteristic, true)) {
deferred.reject(null);
}
changeCharacteristic.put(new CharacteristicKey(characteristic), deferred);
return deferred.promise();
}
// Ignore disabling a notification that isn't enabled.
else {
// Return a successfull result immediately.
deferred = new DeferredObject<Void, Void, BluetoothGattCharacteristic>();
deferred.resolve(null);
return deferred.promise();
}
}