-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New asys APIs #59
New asys APIs #59
Conversation
I don't like the idea of storing a specially encoded file names in a plain string. It's a potential source of errors and confusion, because any string in an application can suddenly become an encoded gibberish instead of a valid string. abstract FilePath(String) from String {
@:from static public function encode(bytes:Bytes):FilePath;
public function decode():Bytes;
}
//and then in sys api:
static public function readDirectory(path:FilePath):Array<FilePath>;
//usage
readDirectory('someDir');
readDirectory(nonUnicodeBytes); And that |
A If we're inside of a string literal in a place where a |
You've done a big work, I would like to know your thoughts behind some of the design changes. Haxe has a lot of other targets besides Node.JS, do we really want to "copy" Node's API? |
My original idea for these APIs was to have the promise variants only. I personally usually use After some discussions (some of which are in the #58 promises proposal), I decided it is indeed best not to go for promises and try to have as minimal of an API as needed for asynchronous operations, which is simply callbacks. Some good arguments against A+ promises (the standard Javascript ones) are here. We could fix some of these without changing the interface too much, but some are really tricky. The "Eager, not lazy" problem as described in the article, for example, cannot be solved without having a Regarding any other style of promises – it is easy for a library to provide a façade over a callback-style API and expose promises instead. The opposite much less so – if you wanted callbacks and only had a promise-based API, you could make it work, but it would be very wasteful, since under the hood the promises would still need to be allocated, garbage collected, etc etc. Regarding tink specifically – I acknowledge tink is a good set of libraries and a lot of work has been put into them. I am sure the asynchrony primitives in tink are well thought out. However, tink is far from atomic, and introducing tink asynchrony into the Haxe standard library would introduce a lot of new concepts that are very specific to tink ( So instead this API has the bare minimum needed, making it easy for libraries to wrap it however you want. Both callbacks and events are abstracts, to at runtime callbacks are simply functions with a specific function signature (always error first), and events are just an array of event handlers. There may be issues with both (please comment if you think of specifics!) but I don't think simply replacing it with a "popular and proven solution" would be the correct way to go.
I have not until now :) I can see it uses tink promises and futures. More importantly, it is just a wrapper which calls the asynchronous versions of functions on Node.js, or uses a runloop (queued synchronous operations) for any other target. The point of this proposal is to provide an interface for asynchronous operations which will be implemented properly (i.e. using native asynchronous calls) on all sys targets.
While I mostly cite Node.js as the reference API here, the actual functions come from libuv. Libuv is a C library, so its API would feel extremely clunky if taken directly into Haxe. Javascript on the other hand has a lot of similarities to Haxe, and the Node.js APIs are simply a very nice way to bring the libuv APIs to Javascript – hence they make good references for Haxe APIs. Very importantly, it would be best to avoid re-inventing the wheel on all targets when implementing these APIs. Simply using libuv on as many sys targets as possible would be ideal. |
Asys is more of a crutch until something like this comes along anyway :) We can easily create a new wrapper that offers all of the async std api using tink's Promises (as mentioned). |
I don't see any mention of AIR api was it studied and considered, I am not really following what Adobe are doing with AIR. But even quite recently Heaps was using AIR so old code may still need maintaining at the very least? See some AIR sys stuff here in relation to your proposal: Event would clash with https://api.openfl.org/openfl/events/Event.html and with Flash target which is still in use, while you can clarify with packages paths this is clumsy for instance dispatching a new type Event from a Sprite? Would SignalEvent be more suitable term? Certainly Signals seems to be a very common term familar with many even in Robert Penners classic book on Signals and Tweens ( tweens are now everywhere but largely they became popular due to the as3 book ). Error does this keyword have implications, if it contains data then would ErrorData, or similar be more suitable and reduce any confusion with native targets? |
Well irrespective of if it could require patches for flash/air a target that you are unlikely to want to fix, I still wonder if Signal is not a more correct term in the wider industry ( outside of whatever node does ) for the use illustrated. Certainly it looked like a simple Signal to me. |
Yes, there is still Flash- and AIR-specific code in Heaps, and maybe other Haxe libraries. Since they use native Flash classes, this proposal does not affect them at all. Even libraries which use the current "pure Haxe" system APIs will not be affected, since the old APIs will not even be deprecated for some time.
I don't think this is much of a problem. This would cause issues with existing code only if there was an
Well, technically,
Please clarify. Why would it introduce confusing with native targets? It is also in the |
A thought on the naming convention of event fields: using |
From what I can tell, these |
@tienery No, there are both synchronous and asynchronous versions in this proposal. They are meant to eventually replace the current APIs which are only synchronous. |
New sys API as a whole has been accepted. Not every detail here is necessarily what we'll end up with 100%, but it still makes sense to merge this as-is. |
Rendered version
See implementation draft.
Changelog:
23. 5.
- changed paths to useFilePath
abstract27. 6.
- changedEvent
toSignal
11. 9.
- changed to separateasys
package, updated feature set