From 09a6da8d55977741b3bcbed7169eade37aac6700 Mon Sep 17 00:00:00 2001 From: R-unic Date: Sun, 10 Sep 2023 18:19:55 -0400 Subject: [PATCH] docs: add example to README --- README.md | 39 +++++++++++++++++++++++++++++++- examples/async-await/src/test.ts | 2 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8811874..74327dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,40 @@ ![build](https://github.com/R-unic/crystallizer/actions/workflows/test.yml/badge.svg) # Crystallizer -A TypeScript to Crystal compiler. All the beauty and power of TypeScript, with all the speed and compatibility of Crystal. +A TypeScript to Crystal compiler. All the beauty and power of TypeScript, with the speed and portability of Crystal. + +# Example +```ts +// examples/async-await/src/test.ts + +async function myAsyncFunction(): Promise { + return "Hello!"; +} + +async function main(): Promise { + myAsyncFunction() // you can also use await here of course + .then(res => console.log(res)); +} + +main(); +``` +```cr +# examples/async-await/dist/test.cr + +private def myAsyncFunction : MiniFuture(String) + async! do + return "Hello!" + end +end +private def main : MiniFuture(Nil) + async! do + myAsyncFunction.then do |res| + puts(res) + end + return + end +end +await main +``` # Usage * All of the below instructions are temporary. @@ -19,6 +53,9 @@ A TypeScript to Crystal compiler. All the beauty and power of TypeScript, with a - destructuring (this is so much harder than it needs to be) - for..in - macro the rest of the `console` library + - macro the `??` operator + - tab size option + - emit comments - disallow: - call expressions on arrow functions directly - type parameters in function types diff --git a/examples/async-await/src/test.ts b/examples/async-await/src/test.ts index aadb3be..38f8c2b 100644 --- a/examples/async-await/src/test.ts +++ b/examples/async-await/src/test.ts @@ -3,7 +3,7 @@ async function myAsyncFunction(): Promise { } async function main(): Promise { - myAsyncFunction() + myAsyncFunction() // you can also use await here of course .then(res => console.log(res)); }