-
Notifications
You must be signed in to change notification settings - Fork 0
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
Async API #26
Comments
Current design used in minisphere is: job = Dispatch.now(asyncFunc); // one-shot, from message pump
job = Dispatch.onUpdate(func); // recurring, once per frame
job = Dispatch.onFlip(func); // recurring, on flipscreen And to stop a pending job from running: job.cancel(); |
How about: let job = new Job(func); also, replace now with once, as it shouldn’t actually execute now but in the next tick.
|
I don't know that it makes sense to have a Also it's awkward: It suggests you can dispatch the same job more than once, but if you do that, what does it mean to do I can rename |
I guess it would make sense to have an undispatched Job object if you want to pass it around for reuse--but in that case you can just pass the function around since JS has first-class functions? I guess it might make sense for extensibility if there were more types of jobs than just "call this function". An interesting proposition, something worth thinking about at least. |
One thing I like about this API setup over, say, the Node.js event system is that it's much easier to cancel jobs. In Node, to remove an event listener you have to keep a reference to the callback around so that you can pass it to removeListener() (which can sometimes be awkward since |
I also added |
You are right, having undispatched is odd, especially when multiple times dispatching. Nvm me :P
|
A useful feature I'm thinking of would be for |
Sphere's internal event loop has long been exposed to the API in a rudimentary capacity. Sphere 1.x has
SetUpdateScript()
andSetRenderScript()
, which only work in the map engine. minisphere broughtDispatchScript()
to the table, renamed tosystem.dispatch()
in minisphere 4.0, which queues a function to be called on the next engine tick (in practice, on the nextFlipScreen()
). Async has always been kind of an afterthought in Sphere, because Sphere games have historically been written like C--largely sequential, often with independent "event loops" intermingled with game logic.If we want to move Sphere forward though, we have to start thinking in terms of async and a central event loop. Platforms like the Web are async-only, and a system like Sphere 1.x would never work in a browser, as has been brought up many times before on the forums.
For my part, I'm implementing an API in minisphere which expands on
system.dispatch()
to allow more control over the event queue. For example, you'd be able to set up recurring jobs (such as update and render code), and later cancel those if needed.This issue is to discuss alternatives for a standardized API for such a system. Developers would be able to use such a system to write code which would work both in minisphere as well as a potential "Web Sphere" which implemented the same API, with no changes.
The text was updated successfully, but these errors were encountered: