I hereby claim:
- I am hitsthings on github.
- I am hitsthings (https://keybase.io/hitsthings) on keybase.
- I have a public key ASBWdlHf_rABh8nhnp5p1MPIUZ-vmbBgj11PEhgkLeHu7Ao
To claim this, I am signing this object:
Copyright (c) <year>, <copyright holder> | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright | |
notice, this list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright | |
notice, this list of conditions and the following disclaimer in the | |
documentation and/or other materials provided with the distribution. |
var toArray = Function.prototype.call.bind(Array.prototype.slice); | |
function partial(fn/*, ...args*/) { | |
var args = [].slice.call(arguments, 1); | |
return function() { | |
var lastArgs = toArray(arguments); | |
return fn.apply(this, args.concat(lastArgs)); | |
}; | |
} |
// -- bit excessive for this case, but the example isn't realistic in the first place | |
export const probability = () => Math.random(); | |
// -- some other file | |
export const diceRoll = () => Math.ceil(probability() * 6); | |
// -- some other file | |
export const coinFlip = () => probability() > 0.5 ? 'heads': 'tails'; | |
// -- shared state can be stored however you like (this is just one example) |
I hereby claim:
To claim this, I am signing this object:
Turns out JS can throw an error on a line like return 42
;
generator
- loops forever sleeping 1s at a time, and when you try to stop it, it waits 1s and then throws an error.
iteration
- calls generator
via a for-await
and attempts to return
within the iteration. This forces iteration
to wait for generator
s finally
section to run which includes a 1s await!