Git Product home page Git Product logo

enroscar-async's Introduction

Enroscar Async

Makes it easy to put your asynchronous operations behind Android's Loader.

Main abstraction here is Async which represents some asynchronous operation.

How it is used

Read our recipes page. Here is a quick overview.

Describe an asynchronous operation.

class Foo {
  @Load Async<String> loadGreeting(final String name) {
    return Tools.async(new Callable<String>() {
      public String call() {
        try { Thread.sleep(1000); } catch (InterruptedException ignored) { }
        return "Hello " + name;
      }
    });
  }
}

In this example we create a simple Callable and pass it to Tools.async method that constructs an Async implementation running our Callable in Android's AsyncTask.

An annotations processor generates an operator class FooOperator that can be used to start/cancel your operations or subscribe to their execution results. Use it!

// this an object that provides operations
Foo foo = new Foo();

// prepare the operator
// FooOperator is a generated class
FooOperator operator = FooOperator.build()
    .withinActivity(activity)
    .operations(foo)
    .get();

// subscribing
operator.when().loadGreetingIsFinished()
    .doOnResult(new Action<String>() {
      @Override
      public void act(final String greeting) {
        Log.i("Async", "Greeting loaded: " + greeting);
      }
    });

// starting
operator.loadGreeting();

// cancelling
operator.cancelLoadGreeting();    

Note that working with an operator you actually control an Android Loader. Hence, using it within an Activity or Fragment you do not care about their lifecycle. Actions you provide subscribing to operations will be automatically attached to running tasks during Activity recreation.

Download

Maven Central

Gradle

compile 'com.stanfy.enroscar:enroscar-async:{latestVersionHere}'
// annotation processor should be added to 'provided' configuration
// it will not be included to your apk
provided 'com.stanfy.enroscar:enroscar-async-compiler:{latestVersionHere}'

To use it with RxJava you'll also need

compile 'com.stanfy.enroscar:enroscar-async-rx:{latestVersionHere}'
compile 'com.netflix.rxjava:rxjava-core:{latestVersionHere}'

License

 Copyright 2011-2015 Stanfy Corp.

 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.

enroscar-async's People

Contributors

vandalko avatar roman-mazur avatar

Watchers

James Cloos avatar ScriptGO avatar

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.