« first day (2442 days earlier)      last day (2520 days later) » 

11:02 PM
3109
Q: How do I return the response from an asynchronous call?

Felix KlingI have a function foo which makes an Ajax request. How can I return the response from foo? I tried to return the value from the success callback as well as assigning the response to a local variable inside the function and return that one, but none of those ways actually return the response. fu...

 
Can fix it?
 
Can read?
 
cant understand. I'm using NodeJS
@BenFortune Please
 
So?
It's pretty straight forward. You can't return from an asynchronous call, use a callback or a promise.
 
async function foo() { return 123 }
foo().then(val => console.log(val))
I can't 😉
?
 
11:10 PM
@rlemon do one
 
still cant understand both thing.
I would really appreciate an example fix
 
:P
you can see the panic set in
 
Invalid attempt to destructure non-iterable instance
function calculateBearing(prox) {
	//function by copy
	//takes an array of bearings, and accesses them via
	return ["n", "ne", "e", "se", "s", "sw", "w", "nw"][(prox + 360 / 16) % 360 / (360 / 8) | 0];
}
What
 
@BenFortune
 
@AbrarAhmed
 
11:15 PM
@SterlingArcher nothing wrong there
wrong line?
 
> at /Users/jordan.alexander/Desktop/Source-React/routes/io-functions.js:8:585
that's where the stack trace points O.o
 
"use strict";

function foo() {
	return ["n", "ne", "e", "se", "s", "sw", "w", "nw"][(prox + 360 / 16) % 360 / (360 / 8) | 0];
}
babel doesn't try to interpret it as a destructuring on the repl
which makes sense
there is no =
 
Maybe the stack trace is lying
the only destructuring I'm doing is
let [x=0,y=0] = movement[data.direction];
 
stack traces are bastards
 
And you wrote that lol
const movement = {
		'nw':[-1,1],
		'ne':[1,1],
		'n':[0,1],
		'sw':[-1,-1],
		'se':[1,-1],
		's':[0,-1],
		'w':[-1,0],
		'e':[1,0]
	};
 
11:17 PM
objects are not iterable.
without plugins
 
So I can't destructure that anymore?
 
object-rest-spread might allow it?
and there is a stage-? proposal for it
but I don't know if node currently supports it by itself.
 
{
	"presets": [
		"react",
		"es2015",
		"stage-1",
		"stage-0",
		"stage-2"
	],
	"plugins": ["transform-class-properties"]
}
my babelrc has all the stages iirc
 
> proposal
try with object-rest-spread
I don't know if it is a plugin or a preset
 
Still cant fix it @BenFortune
 
11:24 PM
@AbrarAhmed I'd suggest learning asynchronous programming before you do anything.
 
how is npm not finding the readme? 0.o
I ran npm publish after the last git push
and there's no .npmignore
 
@towc You didn't bump your version?
 
I tried npm version minor after I noticed there was no readme
if that's not what you mean, what do you mean?
 
Are we working on Jordan's game?
 
oh, it automagically appeared now
anyway, I made a thing :3 npmjs.com/package/real-maths
 
11:39 PM
All it does is add TAU?
Bad
 
not really
 
Yes
 
it's supposed to add a new standard for the naming of the object itself
 
ohhhhhh
that I actually agree with
 
maybe I need to make it more explicit
 
11:40 PM
probably not. I'm not sober
 
for a change. That explains it
 
const Maths = Object.assign(Math, { Tau: Math.PI*2 });
 
that's not theatrical enough
 
but it adds Tau to Math too
backwards compatibility++
 
you're not wrong
 
11:42 PM
I can argue anything
 
also, did the behaviour of a % b change recently?
 
not that I know of
 
I seem to remember there being unintuitive behaviour with negative numbers
 
especially since I just used it today to create jordan's radar
 
but I just tried the main things I could think of and everything seemed fine
I think it used to do something like -7 % 3 // -7 or something
 
11:49 PM
!!> -6 % -2
 
@ndugger 0
 
maybe I just expected the result to always be positive
which would make more sense
unless the base was negative, in which case the result should always be negative
num % base
 
!!> -1 % 2
 
@ndugger -1
 

« first day (2442 days earlier)      last day (2520 days later) »