All Projects → crawlinknetworks → android-promise

crawlinknetworks / android-promise

Licence: Apache-2.0 License
A Javascript style Promise library for Android JVM

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to android-promise

nice-grpc
A TypeScript gRPC library that is nice to you
Stars: ✭ 120 (+421.74%)
Mutual labels:  promise
debounce-async
A debounce function that delays invoking asynchronous functions.
Stars: ✭ 21 (-8.7%)
Mutual labels:  promise
queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
Stars: ✭ 56 (+143.48%)
Mutual labels:  promise
promise
Common interface for simple asynchronous placeholders.
Stars: ✭ 66 (+186.96%)
Mutual labels:  promise
swear
🙏 Flexible promise handling with Javascript
Stars: ✭ 56 (+143.48%)
Mutual labels:  promise
arraync
Async Array methods polyfills
Stars: ✭ 16 (-30.43%)
Mutual labels:  promise
oledb
A small promised based module which uses edge.js to connect to an OLE DB, ODBC or SQL database.
Stars: ✭ 28 (+21.74%)
Mutual labels:  promise
node-steamapi
A nice Steam API wrapper for nodejs
Stars: ✭ 112 (+386.96%)
Mutual labels:  promise
popyt
A very easy to use Youtube Data v3 API wrapper.
Stars: ✭ 42 (+82.61%)
Mutual labels:  promise
purescript-promises
An alternative effect monad for PureScript.
Stars: ✭ 23 (+0%)
Mutual labels:  promise
event-worker
A simpler way of dealing with Web Workers
Stars: ✭ 18 (-21.74%)
Mutual labels:  promise
promise
A step by step implementation practice of Promise class
Stars: ✭ 31 (+34.78%)
Mutual labels:  promise
Actuate
One line easy actuation of CSS animation sequences
Stars: ✭ 42 (+82.61%)
Mutual labels:  promise
Promise
Asynchronous Programming with Promises
Stars: ✭ 15 (-34.78%)
Mutual labels:  promise
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-8.7%)
Mutual labels:  promise
sfdx-lightning-api-component
⚡️ Promise-based service component for calling REST API from Lightning Aura Components without Named Credentials.
Stars: ✭ 62 (+169.57%)
Mutual labels:  promise
redis-memolock
Redis MemoLock - Distributed Caching with Promises
Stars: ✭ 63 (+173.91%)
Mutual labels:  promise
bitmex-orderbook
The fastest order book implementation for the BitMEX WebSocket API.
Stars: ✭ 73 (+217.39%)
Mutual labels:  promise
chomex
Chrome Extension Messaging Routing Kit / Promisify Chrome Messaging / LocalStorage Object Mapper
Stars: ✭ 41 (+78.26%)
Mutual labels:  promise
lifx-http-api
💡 Thin wrapper around the Lifx HTTP API (http://api.developer.lifx.com/)
Stars: ✭ 17 (-26.09%)
Mutual labels:  promise

android-promise :

A Javascript style JAVA Promise library for Android JVM.

  • Simply copy the Promise.java and past in your source foulder, it will work.
promiseObject
      .then()
      .then()
      .then()    // Do task one after another 'n' number of chain
      .error();

How it works ?

doSomeTask(int someValue, String extra)
    .then(res -> doSecondTask((MyObject) res))       // res is result form doSomeTask()
    .then(res -> doThirdTask((OtherObject) res)))    // res is result form doThirdTask()
    .then(res -> doFourthTask((int) res)))           // res is result form doThirdTask()
    .then(res -> doFivethTask())
    .then(res -> {
         // Consume result of the previous function
         return true;    // done
    })
    .error(err -> handleError());                    // Incase of any p.reject() call from above function error will be available here 
public Promise doSomeTask(int someValue, String extra){
    Promise p = new Promise();
    new Thread(()->{
        // do some background operation.
        // When your work done, resolve the promise like below;
        // After resolve the library will pass the value to doSecondTack()
        // Suppose your resultant value is instance of MyObject, then
        // When it is error call reject() with some error message or an Exception
        // p.reject("Some Error happened")
        
        MyObject myObject = new MyObject();
        p.resolve(myObject);
    });
    return p;
}

public OtherObject doSecondTask(MyObject myInput) {
    // Do some syncronous or asyncronous task and return the result,
    // Still it work with your promise chain.
    // Folloing snipet is just a sample work flow
    
    OtherObject obj = new OtherObject();
    
    return obj;
}


public Promise doThirdTask(OtherObject otherObject){
    // Do some task, return value using promise
    Promise p = new Promise();
    
    // Your task
    
    p.resolve();
    
    return p;
}

public Promise doFourthTask(){
    return doSomePromisableTask();    // I am not writing defination of this fuction, let this function is very similar to 
                                      // `doSomeTask()` function
}

public Promise doFivethTask(){
    return doSomePromisableTask()
          .then(res -> {
              // Do some task here
              return 1;      // this one will be available in the next the or parent then which called this task
          });
}

How to use in android?

Download the source file add into your project src.

Promise.java Simply Copy this file into your project

*It need JAVA 1.8 to compile

Description

The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.

A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.

For more information on Javascript Promise please visit the official Mozilla Promise documentation

@see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

This Android Promise Library slightly different than the native Javascript Promise. This promise object has two imprtant method i.e. `resolve()` and `reject()`, whenevey you done withe your process just call resolve or reject function based on your state. The resultant value will be automaticall passed as argument to the followng `then()` or `error()` function.

You can write `n` numbers of `then()` chain.

It supports above JAVA 1.8

LICENCE

  Copyright (c) 2017 CRAWLINK NETWORKS PVT. LTD.

  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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].