[Question]
  [
Your task today is to implement a time limit for getting input, a task I've found rather annoying to achieve in most languages.
You will create a program function which prompts the user for input. Immediatly after the user supplies input, print the message `input received` and end execution/return. However, if the user waits for more than 10 seconds to provide input, output the message `no input received` and end execution/return.
Input must be from `stdin` (the console) or equivalent, not function or program arguments, however output can be either to `stdout`, your function's return value, or any other accepted output method.
You may ask for any amount of input, it can be a single character, a line, a word, or whatever method is shortest in your language as long as it waits for at least one character.
You must output as soon as the input is received, not after the 10 seconds have passed.
After 10 seconds have passed, you *must* end, you cannot continue waiting for input after `no input received` has been printed.
You may assume that input is not passed in the time between 10 seconds elapsing and text being printed to the screen, as this is an extremely small window. You may also assume that your language's builtin equivalent of `sleep` is consistently, absolutely perfect.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), fewest bytes wins!
  
[Answer]
## bash, 38 bytes
```
read -t10||a=no;echo $a input received
```
This uses the `-t` (timeout) option to bash's `read`, which causes it to fail and return a nonzero exit code if no input is given in the specified number of seconds.
[Answer]
## Haskell, ~~97~~ 89 bytes
```
import System.Timeout
timeout(10^7)getChar>>=putStr.(++"input received").maybe"no "mempty
```
If `timeout` times out it returns `Nothing` and `Just Char` (`Char`, because we're using `getChar`) otherwise. This return value is converted to `"no "` or `""` by function `maybe "no " mempty`. Append `"input received"` and print.
Edit: @BMO suggested `maybe` and saved some bytes.
[Answer]
# POSIX C99, 71 63 bytes
```
main(){puts("no input received"+3*poll((int[]){0,1},1,10000));}
```
Ungolfed:
```
#include <unistd.h>
#include <poll.h>
#include <stdio.h>
int main()
{
  struct pollfd pfd; 
  pfd.fd = STDIN_FILENO; 
  pfd.events = POLLIN;  
  puts("no input received"+3*poll(&pfd,1,10000));
}
```
Since `poll` will return 1 in case of success, we multiply the result by 3 and shift the string accordingly. Then, we use the fact that `struct pollfd` has the following layout:
```
     struct pollfd {
     int    fd;       /* file descriptor */
     short  events;   /* events to look for */
     short  revents;  /* events returned */
 };
```
and that `STDIN_FILENO` is `0`, `POLLIN` is `1` to replace `pfd` with `int pfd[] = {0,1}`, which we finally make a compound litteral (as allowed by C99).
[Answer]
# Applescript, 113
Applescript doesn't really do reading from STDIN. Hopefully a `display dialog` is acceptable here:
```
({"","no "}'s item((display dialog""default answer""giving up after 10)'s gave up as integer+1))&"input received"
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~41~~ 40 bytes
```
'no input received'↓⍨{3*⍨⎕RTL←10::0⋄3⊣⍞}
```
This is an anonymous tacit function which [needs a dummy argument to run](https://codegolf.meta.stackexchange.com/a/12696/43319).
`'no input received'` the full string
`↓⍨` drop as many characters from the front of that as the number returned by the
`{` anonymous explicit function (`⍵` denotes the argument)
 `⎕RTL←10` set **R**esponse **T**ime **L**imit to ten seconds
 `3*⍨` raise that number (ten) to the power of three (a thousand means "all")
 `::` upon those exceptions (all),
  `0` return 0
 `⋄` try:
  `⍞` get input
  `3⊣` discard that and instead return 3
`}` end of function (note that the argument `⍵` was never mentioned)
[Answer]
# [Perl](http://perl.org), ~~74~~ 67 bytes
```
$m="input received";$SIG{ALRM}=sub{die"no $m\n"};alarm 10;<>;say$m
```
### Old Version
```
$m="input received";$SIG{ALRM}=sub{die "no $m\n"};alarm 10;<stdin>;say $m;
```
(Run via perl -M5.10.1 ...)
[Answer]
# [Perl 6](https://perl6.org), ~~72~~ 66 bytes
```
my $s='input received';Promise.in(10).then:{say "no $s";exit};get;say $s
```
[Try it with no input](https://tio.run/##HY3BSsQwFEX3/YrLWKjOoujGRcIsXDhaEBX1B8LkOQmTvpTkjRpKv71GV5dzD5c7UQq36wU@zYlgcM6UIM4IbKTMnUDKVAUXcZ6PTbu9e3vYD0/379ih3Q7PNQ7B5Ayl4DOGF6UeDdtAmBtgJHHR4kjyj0CIccKMD5fI2L54ChZLNUuz9Ezfeh0L2rzrPE9nQaID@S@ynX5NcfSZes@XN9dXvThiNWdTsOFYBxtNP14WXY/0X9vmdf0F "Perl 6 – Try It Online")  
[Try it with input](https://tio.run/##HY0xbsJAFER7n2LkWCJQWKGh2BVFCgiWohBBm2aFP/GK9dra/53EQr5MOAdn4gjOhmo0T5o3LQW3GB9wNCeCQccUIJURSN8S43b93ZBzze16gfEl2kDMkQeSLvgkmz3vXtbF62qPJbJZ8Rbj4AwzlIJlFFulNnHnCOcEqEmqpsQnyb0C6V3@4dPYhmTIPX3rse6R8XJifdtJPDqQ/aJyot9DU1um3PrH@dM0l4q8OrPpkfomDlJNP1YGHeX6n2Y8jn8 "Perl 6 – Try It Online")
```
my$s='input received';start {sleep 10;say "no $s";exit};get;say $s
```
[Try it with no input](https://tio.run/##HY3NagIxFIX38xQHDQy4EN10McGFC38GpIW2LxDM1QnGJORe2waZZ58GV4fvfHBOouzfpjku5kYweDBlyGAENhKHViAlVRGKDC5cG7XYfh72/Wn3hQ3Uon@vcfaGGV0Hx@g/uu5ogvWEZwPcSYZocSV5IeBjTHjie8hk7LI48hZjNWMzLgP96uleFG9aF9JDkOlM7odsq1lMrhPsiRLWK82mYBYiFM80/TkZdb14tYqn6R8 "Perl 6 – Try It Online")  
[Try it with input](https://tio.run/##HY1BisJAFET3OUURGwQXw7hxkcaFC2cMiIJu3TTmq8G20/T/UYPkMnoOz@QRYpNVUQ/qladgJ90AB3MmGNRMAXIyAmk8MT7v54KsrT7vF4wr4AMxRx5I6uASNZpt/v/y5XyLKdQoX8XYW8OMLEPJyNdZtog7S3gkwIXkVBU4kvQVSHv5zqWxtUn74@imu0ujeDosna8l/uypvFIx1CwmxBlbIo/xr2bTIHUVFKea7qW0Omp7qrjrvg "Perl 6 – Try It Online")
```
my $s = 'input received'; # base message
start {         # create a Promise with a code block
                # that is run in parallel
  sleep 10;     # delay for 10 seconds
  say "no $s";  # say ｢no input received｣
  exit          # exit from the process
}
get;            # get a line from the input
say $s          # say ｢input received｣
```
[Answer]
# C#, ~~180~~ ~~171~~ ~~148~~ 131 bytes
```
()=>{var t=new System.Threading.Thread(()=>{System.Console.ReadKey();});t.Start();return(t.Join(10000)?"":"no ")+"input recieved";}
```
*Saved 17 bytes thanks to @VisualMelon.*
Full/Formatted version:
```
class P
{
    static void Main()
    {
        System.Func<string> f = () =>
        {
            var t = new System.Threading.Thread(() =>
            {
                System.Console.ReadKey();
            });
            t.Start();
            return (t.Join(10000) ? "" : "no ") + "input recieved";
        };
        System.Console.WriteLine(f());
        System.Console.ReadLine();
    }
}
```
[Answer]
# TI-BASIC, ~~84~~ 77 bytes
-7 thanks to [@kamoroso94](https://codegolf.stackexchange.com/users/57013/kamoroso94)
```
:startTmr→T         //Start Timer, 5 bytes
:Repeat checkTmr(T)=10 or abs(int(.1K)-8)≤1 and 1≥abs(3-10fPart(.1K  //Loop until the timer is 10 seconds or a number key is pressed, 32 bytes
:getKey→K           //get key code, 4 bytes
:End                //end loop, 2 bytes
:"NO INPUT RECEIVED //Push string "NO INPUT RECEIVED" to Ans, 18 bytes
:If K               //If input was received, 3 bytes
:Disp sub(Ans,3,15  //Diplay "INPUT RECEIVED", 9 bytes
:If not(K           //If no input, 3 bytes
:Ans                //Display "NO INPUT RECEIVED", 1 byte
```
Waits until a number is pressed.
I am trying to figure out how to golf the sequence `{72,73,74,82,83,84,92,93,94}`. It is taking up a lot of space.
[Answer]
# NodeJS, ~~105~~ ~~103~~ 101 bytes
*-2 bytes thanks to @apsillers*  
*-2 bytes by moving `console.log()` into `exit()`*
```
with(process)stdin.on('data',r=x=>exit(console.log((x?'':'no ')+'input received'))),setTimeout(r,1e4)
```
Run by saving to a file and running it with node or run it straight from the command line by doing `node -e "<code>"`
[Answer]
# Go, 149 bytes
```
package main
import(
."fmt"
."time"
."os"
)
func main(){
o:="input received"
go func(){Sleep(1e10)
Print("no "+o)
Exit(0)}()
i:=""
Scan(&i)
Print(o)}
```
[Answer]
# [AHK](https://autohotkey.com/), ~~67~~ 65 bytes
*2 bytes saved by [Blauhirn](https://codegolf.stackexchange.com/q/125332//125348?noredirect=1#comment308732_125348)*
```
InputBox,o,,,,,,,,,10
s:=ErrorLevel?"no ":
Send %s%input received
```
AHK has a built-in timeout for input boxes.  
I tried to get clever and use `!o` instead of `ErrorLevel` but that fails if the user inputs a falsey value.  
Almost half of the answer is just the command names and fixed text.
[Answer]
# JavaScript (ES6) + HTML, ~~86~~ ~~84~~ ~~82~~ 79+11 = ~~97~~ ~~95~~ ~~93~~ 90 bytes
```
setTimeout(oninput=_=>i.remove(alert(`${i.value?"":"no "}input received`)),1e4)
```
```
<input id=i
```
* 2 bytes saved thanks to [apsillers](https://codegolf.stackexchange.com/users/7796/apsillers) pointing out that I'm dumb!
---
## Try it
Requires a closing `>` on the `input` in order to work in a Snippet.
```
setTimeout(oninput=_=>i.remove(alert(`${i.value?"":"no "}input received`)),1e4)
```
```
<input id=i>
```
[Answer]
# Python 3, 158 bytes
```
import os,threading as t,time
def k(t=10):time.sleep(t);print("No input received"[(10-t)//3:]);os.kill(os.getpid(),t)
t.Thread(None,k).start()
if input():k(0)
```
[Answer]
## VB.Net - 174 bytes
```
Module M
Sub Main()
Dim t=New Threading.Thread(Sub()Console.Read()):t.Start():Console.WriteLine(If(t.Join(10000),"","no ") & "input received"):End
End Sub
End Module
```
COBOL version coming tomorrow ;-)
[Answer]
# Python3, ~~100~~ ~~89~~ ~~83~~ 71 bytes
```
import pty
print("no input received"[3*any(pty.select([0],[],[],10)):])
```
First try at golfing. 
-4 for `any()`, -7 for slicing, thanks @user2357112!
-6, get `select()` from `pty` instead of `select`. 
[Answer]
## PowerShell, 110 bytes
```
$s1=date;while(![console]::KeyAvailable-and($i=((date)-$s1).seconds-lt10)){}
"{0}input received"-f(,'no ')[$i]
```
[Answer]
# Scratch 2/3.x, 41 points ([Explanation](https://codegolf.meta.stackexchange.com/questions/673/golfing-in-scratch))
[![Impatient timer](https://i.stack.imgur.com/LurNL.png)](https://i.stack.imgur.com/LurNL.png)
1: When GF clicked
1: ask [] and wait
1 + 14 chars: say [input received]
1: stop [all v] (note: since "all" was its default setting I counted the block as 1)
1 + 2 digits: wait (10) seconds
1 + 17 chars: say [no input received]
1: stop [all v]
[Answer]
# Scratch 3.0 (scratchblocks3 syntax), 129 bytes/40 [points](https://codegolf.meta.stackexchange.com/questions/673/golfing-in-scratch)
Beats @Syntax Error's answer by 1 point, but loses to it by 8 bytes.
```
define
broadcast[w v
ask[]and wait
say[input received
stop[all v
when I receive[w v
wait(10)secs
say[no input received
stop[all v
```
Ungolfed:
```
define // custom blocks (functions) do not need names. functions are shorter than programs when counting bytes, because programs that run require "when gf clicked"
broadcast [w v]
ask [] and wait // contrary to what the name of this block would suggest, there is no "ask [] (without waiting)" block - this is why the broadcast is necessary to allow other blocks to run while this block is waiting
say [input received]
stop [all v]
when I receive [w v]
wait (10) secs // although the actual block reads 'seconds', 'secs' is valid in scratchblocks syntax
say [no input received]
stop[all v]
```
[Answer]
## Tcl, 99 bytes
```
after 10000 {set () no}
vwait [fileevent stdin r {gets stdin (x)}]
puts [lappend () input received]
```
[Answer]
# SmileBASIC 3, 74 bytes
"Accepts input" by waiting for any button press (that should count as input.)
```
M=MAINCNT@L
N=MAINCNT-M>599CLS?"NO "*N;"INPUT RECEIVED
ON N+BUTTON()GOTO@L
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 43 + 6 = 49 bytes
```
a/!/i0(?\~"input recieved"r>o<
o "\?:-1/r"n
```
[Try it online!](https://tio.run/##S8sszvj/P1FfUT/TQMM@pk4pM6@gtEShKDU5M7UsNUWpyC7fhitfQSnG3krXUL9IKQ@o@L9uYomegQUA "><> – Try It Online")
+5 for the `-t.08` flag, which sets the tick to 0.08 seconds, and +1 for the `a` flag, which counts whitespace and skipped instructions as ticks.
The program checks for input about once every second, and exits the loop if input is detected. If input is not received, it exits the loop from the bottom, appending `no` to the beginning of the string. The initial `/` is to ensure that the last check for input is exactly on the 10 second mark.
It then takes about 5-6 seconds to print the string itself.
[Answer]
# Java 1.4+, 284 bytes
```
import static java.lang.System.*;public class X{public static void main(String[]x){new Thread(){public void run(){try{Thread.sleep(10000L);}catch(Exception e){}out.print("no input recieved");exit(0);}}.start();new java.util.Scanner(System.in).nextLine();out.print("input recieved");}}
```
**Ungolfed:**
```
import static java.lang.System.*;
public class InputAndWait {
    public static void main(String[] x) {
        new Thread() {
            public void run() {
                try {
                    Thread.sleep(10000L);
                } catch (Exception e) {
                }
                out.print("no input recieved");
                exit(0);
            }
        }.start();
        new java.util.Scanner(System.in).nextLine();
        out.print("input recieved");
    }
}
```
---
Please don't suggest Version-specific Java improvements, this is a generic Java answer that works in all currently stable Java Environments (1.4 and above).
---
Very freaking wordy... The catch is required, can't throw it. System import shaves off like 5 bytes... Overloading is also wordy, so it ends up a wordy poorly-golfed-looking mess.
[Answer]
# [Julia 0.6](http://julialang.org/), 78 bytes
Longer than I expected. See comments for "no input recieved" TIO link.
```
s="input recieved"
Timer(x->(show("no "*s);exit()),10)
readline(STDIN)
show(s)
```
[Try it online!](https://tio.run/##yyrNyUw0@/@/2FYpM6@gtEShKDU5M7UsNUWJKyQzN7VIo0LXTqM4I79cQykvX0FJq1jTOrUis0RDU1PH0ECTqyg1MSUnMy9VIzjExdNPkwussljz/38A "Julia 0.6 – Try It Online")
[Answer]
# SmileBASIC, ~~74~~ 73 bytes
```
M=MAINCNT
WHILE!I*M>MAINCNT-600I=INKEY$()>"
WEND?"no "*!I;"input received
```
Takes 1 character of input.
And a 39 byte solution which probably isn't valid (doesn't actually accept text input, just has an `OK` button that you can press)
```
?"no "*!DIALOG("",,,10);"input received
```
]