Giter VIP home page Giter VIP logo

hxasync's People

Contributors

botsman avatar bozhko-egor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hxasync's Issues

Type safety / static async check

Would it possible to do so that when @async is used with a function, its type is change, so if @await is not used when calling the function type checking would fail?

Example

@async function returnZero(): Int {
  return 0;
}

var i: Int = @await returnZero(); // compilation succeeds
var p: Promise<Int> = returnZero(); // compilation succeeds
var i2: Int = returnZero(); // compilation fails

Can't work with npm package "acorn" while using webpack

Hello, I'm using haxe to develop a tool project recently, I'm having some trouble with js.lib.promise syntax, after looking up related solutions in the community, I found haxelib hxasync, but I found that the project can't compile when I use it, the log information seems to be due to the npm Acorn library which was dependent on webpack, and the error output is as follows:

C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2490
  throw err
  ^

SyntaxError: Unexpected token (536:19)
    at Parser.pp$4.raise (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2488:13)
    at Parser.pp.unexpected (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:623:8)
    at Parser.pp.expect (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:617:26)
    at Parser.pp$3.parseObj (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2173:14)
    at Parser.pp$3.parseExprAtom (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1994:17)
    at Parser.pp$3.parseExprSubscripts (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1872:19)
    at Parser.pp$3.parseMaybeUnary (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1849:17)
    at Parser.pp$3.parseExprOps (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1791:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1774:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1750:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1761:23)
    at Parser.pp$3.parseExpression (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1722:19)
    at Parser.pp$1.parseStatement (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:777:45)
    at Parser.pp$1.parseBlock (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1040:23)
    at Parser.pp$3.parseFunctionBody (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2362:22)
    at Parser.pp$1.parseFunction (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1132:8)
    at Parser.pp$3.parseExprAtom (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1999:17)
    at Parser.pp$3.parseExprSubscripts (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1872:19)
    at Parser.pp$3.parseMaybeUnary (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1849:17)
    at Parser.pp$3.parseExprOps (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1791:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1774:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1750:19)
    at Parser.pp$3.parseExpression (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1722:19)
    at Parser.pp$3.parseParenExpression (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2025:18)
    at Parser.pp$3.parseParenAndDistinguishExpression (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:2085:16)
    at Parser.pp$3.parseExprAtom (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1978:41)
    at Parser.pp$3.parseExprSubscripts (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1872:19)
    at Parser.pp$3.parseMaybeUnary (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1849:17)
    at Parser.pp$3.parseExprOps (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1791:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1774:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1750:19)
    at Parser.pp$3.parseExpression (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:1722:19)
    at Parser.pp$1.parseStatement (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:777:45)
    at Parser.pp$1.parseTopLevel (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:672:23)
    at Parser.parse (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:529:15)
    at Object.parse (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\node_modules\acorn\dist\acorn.js:3378:37)
    at Parser.processInput (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\tool\bin\split.js:1176:29)
    at new Parser (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\tool\bin\split.js:1162:7)
    at Object.HxSplit.run.$hx_exports.run (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-modular\tool\bin\split.js:1044:15)
    at processOutput (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-loader\index.js:116:10)
    at exec (C:\Users\Xuzx\Desktop\Haxe\OgmoEditor3-CE\node_modules\haxe-loader\index.js:94:27)
    at ChildProcess.exithandler (child_process.js:285:7)

Do you know how to solve it?
You can install the hxasync lib in the Ogmo3 project and write some code in the initialization process for testing

Improve asyncPlaceholder handling

  1. If Haxe function has some default parameters:
private function some(param: String = "asd") {}

then in JS and Python output Haxe adds something like:

if (param == null) {
  param = "asd";
}

and that added code is placed before asyncPlaceholder

  1. In Python Haxe adds sometimes something like
_gthis = self

in the beginning of a function body, before async placeholder.

Probably both cases could be fixed with regexes. In the future would be good to get rid of regexes completely.

Fix error messages

The errors which are thrown inside macros must be "attached" to the place in real code, not to the macros code.

add flag for disabling typing

There are possible errors when trying to get expression type in macros.
Would be good to have a possibility to disable expression typing.

Problem with (@await func()).field

Looks like that the code like the following

var f = (@await func()).field;

is compiled into the following in python

f = await func().field

which raises exception AttributeError 'coroutine' object has no attribute 'field'

Improve type checking

Make sure that:

  1. @async function return type is converted to Awaitable<T>.
  2. @await can only be applied to Awaitable<T> (maybe implement this under some flag, because in JS you can await normal function).
  3. after applying @await expression return type is converted to T.

Async functions can't return Void type

My code:

  @async private function myAsyncFuncReturningVoid(): Void {
    // do something
    // line 244 is here
  }

  @async private function test() {
      @await this.myAsyncFuncReturningVoid(); // line 264 is here
  }

Compiler output:

ex.hx:244: characters 5-38 : Dynamic should be Void
ex.hx:244: characters 5-38 : Dynamic should be Void
ex.hx:264: characters 14-33 : Void should be hxasync.Awaitable<Void>
ex.hx:264: characters 14-33 : ... For function argument 'arg'

Handle Void return type

It seems that currently Void return type is converted to Dynamic.
It does not seem to be a problem, but it would be good to fix anyway.
Need to check whether it is true and try to fix that.

Improve return

I had to return null/None from async functions.

Would be good to keep implementation so that it deletes empty returns.

Type checking

  • If @async is added to the function declaration, convert its return type T to Awaitable<T>

  • If @await is added before Awaitable function call, convert its return type from Awaitable<T> to T

  • Check that @await is used only inside async context.

Add tests

Tests for Python, JavaScript and (later) for any other platform.

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.