From e9bdb7b566c9f0fb6ee5d383cabfa636f9cb1cce Mon Sep 17 00:00:00 2001 From: riversun Date: Thu, 2 May 2019 19:21:14 +0900 Subject: [PATCH] update readme --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ad46bb..fd85ca7 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,58 @@ It is licensed under [MIT](https://opensource.org/licenses/MIT). [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.riversun/java-promise/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.riversun/java-promise) +# Quick Look + +**Writing a Promise in Javascript** + +A typical example of using promise in JavaScript is: + +```JavaScript +Promise.resolve('foo') + .then(function (data) { + return new Promise(function (resolve, reject) { + setTimeout(function () { + const newData = data + 'bar'; + resolve(newData); + }, 1); + }); + }) + .then(function (data) { + return new Promise(function (resolve, reject) { + console.log(data); + }); + }); +console.log("Promise in JavaScript"); +``` + +**Writing a Promise in java-promise** + +Write the same thing using **java-promise** + +```Java +import org.riversun.promise.Promise; +public class Example { + + public static void main(String[] args) { + Promise.resolve("foo") + .then(new Promise((action, data) -> { + new Thread(() -> { + String newData = data + "bar"; + action.resolve(newData); + }).start(); + })) + .then(new Promise((action, data) -> { + System.out.println(data); + action.resolve(); + })) + .start(); + System.out.println("Promise in Java"); + } +} +``` + **Syntax:** -You can write in a syntax similar to JavaScript as follows: +Yes,you can write in a syntax similar to JavaScript as follows: ```Java Promise.resolve()