BoltsFramework /
Bolts-Java
[Archive] Bolts is a collection of low-level libraries designed to make developing mobile apps easier.
Loading repository data…
BoltsFramework / repository
Bolts is a collection of low-level libraries designed to make developing mobile apps easier.
[![Build Status][build-status-svg]][build-status-link] [![Coverage Status][coverage-status-svg]][coverage-status-link] [![Maven Central][maven-tasks-svg]][maven-tasks-link] [![Maven Central][maven-applinks-svg]][maven-applinks-link] [![License][license-svg]][license-link]
Bolts is a collection of low-level libraries designed to make developing mobile apps easier. Bolts was designed by Parse and Facebook for our own internal use, and we have decided to open source these libraries to make them available to others. Using these libraries does not require using any Parse services. Nor do they require having a Parse or Facebook developer account.
Bolts includes:
For more information, see the Bolts Android API Reference.
Download [the latest JAR][latest] or define in Gradle:
dependencies {
compile 'com.parse.bolts:bolts-tasks:1.4.0'
compile 'com.parse.bolts:bolts-applinks:1.4.0'
}
Snapshots of the development version are available in [Sonatype's snapshots repository][snap].
To build a truly responsive Android application, you must keep long-running operations off of the UI thread, and be careful to avoid blocking anything the UI thread might be waiting on. This means you will need to execute various operations in the background. To make this easier, we've added a class called Task. A Task represents an asynchronous operation. Typically, a Task is returned from an asynchronous function and gives the ability to continue processing the result of the task. When a Task is returned from a function, it's already begun doing its job. A Task is not tied to a particular threading model: it represents the work being done, not where it is executing. Tasks have many advantages over other methods of asynchronous programming, such as callbacks and AsyncTask.
Tasks.Tasks in a row will not create nested "pyramid" code as you would get when using only callbacks.Tasks are fully composable, allowing you to perform branching, parallelism, and complex error handling, without the spaghetti code of having many named callbacks.For the examples in this doc, assume there are async versions of some common Parse methods, called saveAsync and findAsync which return a Task. In a later section, we'll show how to define these functions yourself.
continueWith MethodEvery Task has a method named continueWith which takes a Continuation. A continuation is an interface that you implement which has one method, named then. The then method is called when the Task is complete. You can then inspect the Task to check if it was successful and to get its result.
saveAsync(obj).continueWith(new Continuation<ParseObject, Void>() {
public Void then(Task<ParseObject> task) throws Exception {
if (task.isCancelled()) {
// the save was cancelled.
} else if (task.isFaulted()) {
// the save failed.
Exception error = task.getError();
} else {
// the object was saved successfully.
ParseObject object = task.getResult();
}
return null;
}
});
Tasks are strongly-typed using Java Generics, so getting the syntax right can be a little tricky at first. Let's look closer at the types involved with an example.
/**
Gets a String asynchronously.
*/
public Task<String> getStringAsync() {
// Let's suppose getIntAsync() returns a Task<Integer>.
return getIntAsync().continueWith(
// This Continuation is a function which takes an Integer as input,
// and provides a String as output. It must take an Integer because
// that's what was returned from the previous Task.
new Continuation<Integer, String>() {
// The Task getIntAsync() returned is passed to "then" for convenience.
public String then(Task<Integer> task) throws Exception {
Integer number = task.getResult();
return String.format("%d", Locale.US, number);
}
}
);
}
In many cases, you only want to do more work if the previous Task was successful, and propagate any errors or cancellations to be dealt with later. To do this, use the onSuccess method instead of continueWith.
saveAsync(obj).onSuccess(new Continuation<ParseObject, Void>() {
public Void then(Task<ParseObject> task) throws Exception {
// the object was saved successfully.
return null;
}
});
Tasks are a little bit magical, in that they let you chain them without nesting. If you use continueWithTask instead of continueWith, then you can return a new task. The Task returned by continueWithTask will not be considered complete until the new Task returned from within continueWithTask is. This lets you perform multiple actions without incurring the pyramid code you would get with callbacks. Likewise, onSuccessTask is a version of onSuccess that returns a new task. So, use continueWith/onSuccess to do more synchronous work, or continueWithTask/onSuccessTask to do more asynchronous work.
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Student");
query.orderByDescending("gpa");
findAsync(query).onSuccessTask(new Continuation<List<ParseObject>, Task<ParseObject>>() {
public Task<ParseObject> then(Task<List<ParseObject>> task) throws Exception {
List<ParseObject> students = task.getResult();
students.get(0).put("valedictorian", true);
return saveAsync(students.get(0));
}
}).onSuccessTask(new Continuation<ParseObject, Task<List<ParseObject>>>() {
public Task<List<ParseObject>> then(Task<ParseObject> task) throws Exception {
ParseObject valedictorian = task.getResult();
return findAsync(query);
}
}).onSuccessTask(new Continuation<List<ParseObject>, Task<ParseObject>>() {
public Task<ParseObject> then(Task<List<ParseObject>> task) throws Exception {
List<ParseObject> students = task.getResult();
students.get(1).put("salutatorian", true);
return saveAsync(students.get(1));
}
}).onSuccess(new Continuation<ParseObject, Void>() {
public Void then(Task<ParseObject> task) throws Exception {
// Everything is done!
return null;
}
});
By carefully choosing whether to call continueWith or onSuccess, you can control how errors are propagated in your application. Using continueWith lets you handle errors by transforming them or dealing with them. You can think of failed Tasks kind of like throwing an exception. In fact, if you throw an exception inside a continuation, the resulting Task will be faulted with that exception.
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Student");
query.orderByDescending("gpa");
findAsync(query).onSuccessTask(new Continuation<List<ParseObject>, Task<ParseObject>>() {
public Task<ParseObject> then(Task<List<ParseObject>> task) throws Exception {
List<ParseObject> students = task.getResult();
students.get(0).put("valedictorian", true);
// Force this callback to fail.
throw new RuntimeException("There was an error.");
}
}).onSuccessTask(new Continuation<ParseObject, Task<List<ParseObject>>>() {
public Task<List<ParseObject>> then(Task<ParseObject> task) throws Exception {
// Now this continuation will be skipped.
ParseObject valedictorian = task.getResult();
return findAsync(query);
}
}).continueWithTask(new Continuation<List<ParseObject>, Task<ParseObject>>() {
public Task<ParseObject> then(Task<List<ParseObject>> task) throws Exception {
if (task.isFaulted()) {
// This error handler WILL be called.
// The exception will be "There was an error."
// Let's handle the error by returning a new value.
// The task will be completed with null as its value.
return null;
}
// This will also be skipped.
List<ParseObject> students = task.getResult();
students.get(1).put("salutatorian", true);
return saveAsync(students.get(1));
}
}).onSuccess(new Continuation<ParseObject, Void>() {
public Void then(Task<ParseObject> task) throws Exception {
// Everything is done! This gets called.
// The task's result is null.
return null;
}
});
It's often convenient to have a long chain of success callbacks with only one error handler at the end.
When you're getting started, you can just use the Tasks returned from methods like findAsync or saveAsync. However, for more advanced scenarios, you may want to make your own Tasks. To do that, you create a TaskCompletionSource. This object will let you create a new Task and control whether it gets marked as completed or cancelled. After you create a Task, you'll need to call setResult, setError, or setCancelled to trigger its continuations.
public Task<String> succeedAsync() {
TaskCompletionSource<String> successful = new TaskCompletionSource<>();
successful.setResult("The good result.");
return successful.getTask();
}
public Task<String> failAsync() {
TaskCompletionSource<String> failed = new TaskCompletionSource<>();
failed.setError(new RuntimeException("An error message."));
return failed.getTask();
}
If you know the result of a Task at the time it is created, there are some convenience methods you can use.
Task<String> successful = Task.forResult("The good result.");
Task<String> failed = Task.forError(new RuntimeException("An error message."));
With these tools, it's easy to make your own asynchronous functions that return Tasks. For example, you can define fetchAsync easily.
public Task<ParseObject> fetchAsync(ParseObject obj) {
final TaskCompletionSource<ParseObject> tcs = new TaskCompletionSource<>();
obj.fetchInBackground(new GetCallback() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
tcs.setResult(object);
} else {
tcs.setError(e);
}
}
});
return tcs.getTask();
}
It's similarly easy to create saveAsync, findAsync or deleteAsync. We've also provided some convenience functions to help you create Tasks from straight blocks of code. callInBackground runs a Task on our background thread pool, while call tries to execute its block immediately.
Task.callInBackground(new Callable<Void>() {
public Void call() {
// Do a bunch of stuff.
}
}).continueWith(...);
Tasks are convenient when you want to do a series of asynchronous operations in a row, each one waiting for the previous to finish. For example, imagine you want to delete all of the comments on your blog.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Comments");
query.whereEqualTo("post", 123);
findAsync(query).continueWithTask(new Continuation<List<ParseObject>, Task<Void>>() {
public Task<Void> then(Task<List<ParseObject>> results) throws Exception {
// Create a trivial completed task as a base case.
Task<Void> task = Task.forResult(null);
for (final ParseObject result : results) {
// For each item, extend the task with a function to delete the item.
task = task.continueWithTask(new Continuation<Void, Task<Void>>() {
public Task<Void> then(Task<Void> ignored) throws Exception {
// Return a task that will be marked as completed when the delete is
Selected from shared topics, language and repository description—not editorial ratings.
BoltsFramework /
[Archive] Bolts is a collection of low-level libraries designed to make developing mobile apps easier.
maxabrahamsson /
Bolt is a java framework for Kinect
Medhansh-32 /
PaperPal is a webapp made using React-TypeScript , Bolt.io(Frontend) and Java, SpringBoot (Backend).This provides students to uplaod study materials and PYQs and people can fetch them according to their details of Course ,Branch and semester , gets AI response on specific prompt provided and post query where people can collaborarte and solve them.
ubaid4j /
Here, I will make a social network in Java and then Integrate it in Neo4J which is graph database Management system Using Bolt API
dvinfosys /
Kotlin is a cutting edge programming dialect that incorporates to Java bytecode. It is free and open source, and guarantees to make coding for Android much more fun. Kotlin is 100% interoperable with Java. At the end of the day, it can be utilized together with Java in a similar venture. So you can refactor parts of your Java code to Kotlin and it won't break. Notwithstanding that, it is brief, expressive, and has extraordinary tooling. Kotlin can be utilized toward the back (server-side), however it's getting a great deal of consideration at the present time as a dialect for Android application improvement. Kotlin is currently bolstered by Google as a top of the line dialect for Android improvement, so the fame of Kotlin is set to detonate! In this first instructional exercise in the Kotlin From Scratch arrangement, you'll find out about the dialect nuts and bolts: remarks, factors, basic sorts, clusters, and sort induction.
Laxman-77 /
This is a slack bot created using the slack API and Bolt for java.