Comments (9)
findAsync
and saveAsync
are fictional asynchronous methods, but are similar to ParseQuery#findInBackground()
and ParseObject#saveInBackground()
from the Parse-SDK-Android.
from bolts-android.
Gotcha, so to use it then, I have my own Async method (IE class someTask extends AsyncTask <Void, Void, Void> { ...stufff...} and then use the calls by replacing the findAsync in your examples with my someTask?
from bolts-android.
Kind of, but not really. Task
s do not depend on using AsyncTask
anywhere, but they can be used together.
The most simple way of using Task
s to get something off onto a thread:
public Task<Void> doSomethingAsync() {
return Task.call(() -> {
// do some long running operations such as network operations
}, Task.BACKGROUND_EXECUTOR);
};
If you want to do something upon completion of the asynchronous work, like you would with callbacks, you use continuations:
doSomethingAsync().continueWithTask((t) -> {
if (t.isFaulted()) {
// error case
} else if (t.isCancelled()) {
// canceled case
} else {
// success case
}
return t;
});
from bolts-android.
Ok, I have copied your example here exactly and am getting compiler errors with the doSomethingAsync().continueWithTask((t) call. It reads, "Lambda expressions are not supported at this language level". Is there something I am missing? Is the t a defined variable somewhere? Is there more to your expression but Android Studio cut it off?
from bolts-android.
Sorry I'm using Java 8 lambda short hand when typing these out.
(t) -> {
// ...
}
can be replaced with
new Continuation<Void, Task<Void>>() {
@Override public void done(Task<Void> t) {
// ...
}
}
from bolts-android.
Gotcha, perfect, that compiles and works just fine.
Just one more clarification Q for ya, if my goal is to run multiple server requests (Let's say I'm pinging a Rest API like 4 times), would I write 4 separate .continueWithTask((t) connected together and embed network calls within the inner-class? Or run 4 separate oSomethingAsync().continueWithTask()... calls?
from bolts-android.
That really depends on how you want to architect your API. If you're going to make asynchronous methods for each API call, you can chain them together using continueWithTask
, but if this is a one off situation you can also have them all in a single Continuation
.
from bolts-android.
I appreciate your time and expertise. Thank you for the help!
from bolts-android.
No problem, I'm glad I've been able to clear everything up! Have fun using Bolts 😄
from bolts-android.
Related Issues (20)
- API 19 DUPLICATE ENTRY HOT 1
- Task.continueWithTask(task) is not supported?
- Task.BACKGROUND_EXECUTOR is badly defined and prone to lockups HOT 4
- Progress in whenAll() and whenAllResult()
- onSuccessInUi() shortcut for onSuccess(..., Task.UI_THREAD_EXECUTOR)? HOT 1
- Getting OOM
- com.parse.ParseException: bolts.ExecutorException: An exception was thrown by an Executor
- Easier way to unit test background Tasks HOT 1
- continueWhile HOT 3
- What happens when task is running and activity is closed ?
- Are you still updating?
- Update to MIT license HOT 3
- Publish latest version HOT 2
- ssl
- 1.5.0 HOT 3
- Bundle proguard rules
- Hello world
- Cancel a Task.call() with CancellationToken HOT 2
- Get task from TaskCompletionSource without executing it. HOT 3
- How not to start a task when creating it? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bolts-android.