Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29929

Re: Wait on keyboard

Path csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail
From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Wait on keyboard
Date Sat, 12 Mar 2016 11:21:51 +0100
Organization albasani.net
Lines 37
Message-ID <nc0qjv$b4e$1@news.albasani.net> (permalink)
References <6ef267d6-7655-4699-9363-d6e0f613f899@googlegroups.com> <nbuq32$gg0$1@news.albasani.net> <9658502.p6PyTM0SGn@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net 0yH08t5o7NgEnpljMFW0IoT0JjLuL+9lR6aAJ67uH7I36LUasiunmeGIiFrkSJNQf8aB1HDXIkkDYmZjJcNlUnk2pPJ6CtrBbhZ6f6Ax2ilY/w7y/onmQwPK5tVZyHF1
NNTP-Posting-Date Sat, 12 Mar 2016 10:21:52 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="FhbLdtalyUYYjnQkLufAf+FYT2BTlkc8uS9hTHvXyNaKwRlrYycALyz1WniQhGxUVEBp4nv7PZJeSpgMZXVijTFaneavP7FZ9wwPCZ2jXFV/GOynH2MVisb6aht2Ictu"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <9658502.p6PyTM0SGn@PointedEars.de>
Cancel-Lock sha1:H1B8xBz8mXVW17+R8Q4b8iIz4dE=
X-Enigmail-Draft-Status N1110
Xref csiph.com comp.lang.javascript:29929

Show key headers only | View raw


On 03/12/2016 04:44, Thomas 'PointedEars' Lahn wrote:
> Stefan Weiss wrote:
> 
>> With a little generator magic, you can make individual functions
>> pause-able:
>>
>>     var jonas = S(function* (start, max)
> 
> In which ECMAScript implementation is this not a syntax error, and if there 
> is any, what does it mean there?

That's the generator function syntax:
http://www.ecma-international.org/ecma-262/6.0/#sec-generator-function-definitions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*

It's supported by current versions of Firefox, Chrome, Edge (with the
experimental flag), and others:
http://kangax.github.io/compat-table/es6/#test-generators_basic_functionality

>> PS (group): I hacked this function together rather quickly.
> 
> Or is this the explanation for the quoted code?

No, honest request for feedback :)

There's one problem that I'm aware of with this approach: while the
function is paused and waiting for a timeout or event, it's possible to
execute it again:

   jonas(3,4); jonas(5,6);

This calls next() on the same generator for both, exhausting it earlier
than expected, and eventually resulting in "TypeError: gen is null".
I couldn't find a simple solution for this yesterday, so my advice at
the moment is to not do that :)

- stefan

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 02:30 -0800
  Re: Wait on keyboard Tim Streater <timstreater@greenbee.net> - 2016-03-11 10:37 +0000
  Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 02:50 -0800
    Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 03:13 -0800
      Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 03:23 -0800
        Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 03:32 -0800
          Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 03:39 -0800
            Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 04:41 -0800
              Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 05:00 -0800
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 05:43 -0800
      Re: Wait on keyboard Tim Streater <timstreater@greenbee.net> - 2016-03-11 12:13 +0000
  Re: Wait on keyboard "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-11 21:52 +0800
    Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 07:29 -0800
  Re: Wait on keyboard Stefan Weiss <krewecherl@gmail.com> - 2016-03-11 17:00 +0100
    Re: Wait on keyboard Stefan Weiss <krewecherl@gmail.com> - 2016-03-11 17:11 +0100
      Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 08:32 -0800
        Re: Wait on keyboard Stefan Weiss <krewecherl@gmail.com> - 2016-03-11 20:20 +0100
      Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 08:55 -0800
        Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-11 16:30 -0300
          Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 11:46 -0800
            Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 12:22 -0800
              Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-11 17:25 -0300
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 12:32 -0800
                Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-11 17:42 -0300
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 12:52 -0800
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-11 12:47 -0800
                Re: Wait on keyboard "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-11 18:39 -0800
              Re: Wait on keyboard "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-11 18:37 -0800
              Re: Wait on keyboard John Harris <niam@jghnorth.org.uk.invalid> - 2016-03-12 13:16 +0000
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 05:57 -0800
                Re: Wait on keyboard John Harris <niam@jghnorth.org.uk.invalid> - 2016-03-13 10:31 +0000
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 05:55 -0700
                Re: Wait on keyboard "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-13 17:19 +0100
                Re: Wait on keyboard Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-13 13:01 -0700
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 15:19 -0700
                Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-13 20:08 -0300
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 21:45 -0700
                Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-14 01:50 -0300
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 22:39 -0700
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 22:46 -0700
                Re: Wait on keyboard Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-14 11:54 -0700
                Re: Wait on keyboard Tim Streater <timstreater@greenbee.net> - 2016-03-14 08:31 +0000
                Re: Wait on keyboard John Harris <niam@jghnorth.org.uk.invalid> - 2016-03-14 10:43 +0000
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 06:04 -0800
                Re: Wait on keyboard "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-12 15:22 +0100
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 07:46 -0800
                Re: Wait on keyboard Tim Streater <timstreater@greenbee.net> - 2016-03-12 15:52 +0000
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 09:25 -0800
                Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-12 20:16 -0300
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 15:57 -0800
                Re: Wait on keyboard Aleksandro <aleksandro@gmx.com> - 2016-03-12 21:07 -0300
                Re: Wait on keyboard Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-12 21:27 -0800
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-13 03:08 -0700
                Re: Wait on keyboard "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-12 23:30 +0100
                Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 06:15 -0800
            Re: Wait on keyboard "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-11 18:33 -0800
              Re: Wait on keyboard jonas.thornvall@gmail.com - 2016-03-12 03:01 -0800
    Re: Wait on keyboard "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-11 18:30 -0800
    Re: Wait on keyboard Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-12 04:44 +0100
      Re: Wait on keyboard Stefan Weiss <krewecherl@gmail.com> - 2016-03-12 11:21 +0100
        Re: Wait on keyboard Stefan Weiss <krewecherl@gmail.com> - 2016-03-12 11:27 +0100
        Re: Wait on keyboard Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-12 14:44 +0100
    Re: Wait on keyboard "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-14 18:58 +0800

csiph-web