Giter VIP home page Giter VIP logo

Comments (9)

grantland avatar grantland commented on June 12, 2024

findAsync and saveAsync are fictional asynchronous methods, but are similar to ParseQuery#findInBackground() and ParseObject#saveInBackground() from the Parse-SDK-Android.

from bolts-android.

PGMacDesign avatar PGMacDesign commented on June 12, 2024

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.

grantland avatar grantland commented on June 12, 2024

Kind of, but not really. Tasks do not depend on using AsyncTask anywhere, but they can be used together.

The most simple way of using Tasks 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.

PGMacDesign avatar PGMacDesign commented on June 12, 2024

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.

grantland avatar grantland commented on June 12, 2024

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.

PGMacDesign avatar PGMacDesign commented on June 12, 2024

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.

grantland avatar grantland commented on June 12, 2024

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.

PGMacDesign avatar PGMacDesign commented on June 12, 2024

I appreciate your time and expertise. Thank you for the help!

from bolts-android.

grantland avatar grantland commented on June 12, 2024

No problem, I'm glad I've been able to clear everything up! Have fun using Bolts 😄

from bolts-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.