Open CeylonMigrationBot opened 9 years ago
[@tombentley] It can't be system.sleep()
because it's not making the system sleep. It would have to be process.sleep()
. But even then it's semantics on JVM are to make the current thread sleep which isn't quite the same thing. So I'm wondering how you'd specify this.
And how would you implement this on JS?
[@gavinking]
And how would you implement this on JS?
Ah, sorry, you're right, I was thinking of using setTimeout()
but that doesn't quite work. It would have to be implemented using a loop. Hrm.
It seems to me the appropriate platform-neutral approach to this would have to be to use a callback, so you do not assume the platform you're running on has Threads or similar:
sleep(1k, function() {
// after one second, we continue
});
Seems quite reasonable to me. Unless you want to add continuations to the language!
@renatoathaydes Indeed, we could do that. WDYT, @jvasileff, I assume that could be implemented on Dart, right?
The alternative is ugly and can be implemented in pure Ceylon :)
void sleep(Integer millis) {
value ms => system.milliseconds;
value end = ms + millis;
while(ms < end) {}
}
Yeah, I believe that's
Future.delayed(Duration duration, [dynamic computation()])
Creates a future that runs its computation after a delay.
Would the task run on a separate thread on the JVM? If not, these seem like very different functions.
The alternative is ugly and can be implemented in pure Ceylon :)
:-1: my CPU run's hot enough already :smile:
On the JVM, the callback must run in the same Thread, otherwise you run into synchronization issues just for calling sleep.
Ok, but then on JVM it's blocking & precise, and on JS/Dart it's non-blocking and imprecise.
Ugh. That's not great.
Yes, I thought about that... it's a problem if you block.... it must be non-blocking in any platform to be consistent, but the callback must run on the same Thread... kind of a contradiction.
Probably best to leave this to a small library that provides green Threads... I did start on this with the ConcurrenCey project but has been a while I updated that. I might get back to it soon... but it was Java-only... not sure if I can make it work in JS (and Dart).
my CPU run's hot enough already @jvasileff https://xkcd.com/1172/
[@gavinking] I think we should have a
sleep()
function in the language module. This can be implemented in both JS and Java, right?[Migrated from ceylon/ceylon.language#596]