Live data from Hacker News

How to programmatically find out if computer is on

haiku-os.org

41–50 of 197 posts

Re: How to programmatically find out if computer is on

#42
post #22

> If the computer isn't on, the value returned by this function is undefined. Shouldn't it just block until the computer turns back on? Probably interferes with pthreads.

Seems like a reasonable compiler would inline the most likely implementation as 1. So, while technically undefined, it's safe to assume that it will 'return' 1 regardless of the actual on/off state of the computer.

I agree on the implementation, but I'm pretty sure if the computer is off you aren't getting a 1.

Re: How to programmatically find out if computer is on

#43
post #32

Javascript equivalent function is kind of wonky so they had to make is_the_computer_really_on() to do what you want here.

there's a convenient npm package to handle that for you

Yeah but you never know whose computer the result applies to

Re: How to programmatically find out if computer is on

#44

Asynchronous JavaScript browser DOM callback API:

Asynchronous is definitely the way to go. I once tried synchronous code. Had to move it to a service worker so as to not bog down the UI, and you don't even want to know what service workers do when the computer is off. Let's just say it's undocumented.

Re: How to programmatically find out if computer is on

#45

Functional programming with monads is the right way to implement this.

There's an elegant FP solution that involves searching an infinite data structure using only a finite amount of computation -- actually, with precisely zero computation, because the machine isn't on.

It's like lazy evaluation, only more lazy.

Re: How to programmatically find out if computer is on

#47
post #4

Where does the code run when the computer is off? Edit: I see the downvotes, yet i still don't know if it's a joke. I was genuinely asking the question.

Genuine answer: the code cant run when the computer is off, thus the joke.

The question is worth asking (all are) but then soliciting "quantum computing" as an answer makes it a doubly worthy set up line, so thanks twice.

Re: How to programmatically find out if computer is on

#48
post #32

Javascript equivalent function is kind of wonky so they had to make is_the_computer_really_on() to do what you want here.

there's a convenient npm package to handle that for you

And a separate package by the same prolific author for not_on that depends on the first package.

Re: How to programmatically find out if computer is on

#50

Functional programming with monads is the right way to implement this.

There's an elegant FP solution that involves searching an infinite data structure using only a finite amount of computation -- actually, with precisely zero computation, because the machine isn't on. It's like lazy evaluation, only more lazy.

Wait. When the machine isn't on, P=NP!

So our security systems are (useless | perfect)!

I think there might even be other implications...

Post reply on HN