--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I am directly running code. Presently I am working
On Dev box only.
I have made a block on blockly developer tool. I am not sure if block config is correct to accept the output to if conditions.. And proceed to next statement in do. How can it be done.
Please give inputs.
async function runProgram() {window.alert(await new Promise(resolve => {$.ajax({url: "whatever",success: resolve,})}))}runProgram().then(() => {/* if you need to know when it's done, do it here */})The stuff inside of `runProgram` is the generated Blockly code. The subsequent call is an example of how to call the function you created. The `await new Promise` expression is what the code generator for your sensor block would return.This example is just using the default "print" block and attaching your sensor block to it./s/ Adam
On Wed, Apr 10, 2019 at 10:58 PM pratika jain <pratik...@gmail.com> wrote:
Hi Adam,I will try out the options suggested.Will get back to you post trying.It would be great, if you can share some code snippets.Thanks.
On Thu 11 Apr, 2019, 12:52 AM Coda Highland, <chig...@gmail.com> wrote:
By environment, I meant if you're working in Node.JS or in the browser, and which browsers you need to support.The absolute easiest way to do it would be to use the `await` JS keyword and stick the code from the code generator into an `async` function. This works in any browser released since mid-2017, and I think Node 10 supports it. In order to use `await`, though, you need to be using Promises.The simplest way to do THAT is by using fetch() instead of $.ajax(), but that runs into CORS issues, so it might prove to be easier to wrap your code in a promise yourself./s/ Adam
On Wed, Apr 10, 2019 at 2:01 PM pratika jain <pratik...@gmail.com> wrote:
Hi Adam,
Thanks for your reply..
I am directly running code. Presently I am working
On Dev box only.
I have made a block on blockly developer tool. I am not sure if block config is correct to accept the output to if conditions.. And proceed to next statement in do. How can it be done.
Please give inputs.
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blo...@googlegroups.com.
Blockly.JavaScript.addReservedWords('waitForSeconds');
var wrapper = interpreter.createAsyncFunction(
function(timeInSeconds, callback) {
// Delay the call to the callback.
setTimeout(callback, timeInSeconds * 1000);
});
interpreter.setProperty(scope, 'waitForSeconds', wrapper);--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
Yes, switching to using JS Interpreter would definitely make this kind of thing more straightforward, but I don't have any firsthand experience with it while I DO have firsthand experience with async/await. I would advise going with that route because you'll have a lot more community support that way.Regarding the async function, it appears you've misunderstood what I was saying: After you generate JS code from your Blockly code, that generated code needs to be wrapped inside of "async function runProgram", which you then invoke with the example call I put below it.Another thing I would recommend, regardless of which technique you use, is to wrap all of this code in a function, so that the code generator can output a simple function call. After all, a block that returns a value needs to generate code in the form of a JS expression. Using async/await, this worker function would be called as "await getSensor()" or something, and its implementation would "return new Promise" as the sample i showed you before. Using JS Interpreter, the worker function would need to accept a callback parameter./s/ Adam
To unsubscribe from this group and stop receiving emails from it, send an email to blo...@googlegroups.com.
var wrapper = function(callback) {
new Promise(function(callback) {
$.ajax({
url: "https://api.particle.io/v1/devices/" + 'DEVICEID' + "/sensor_value/?access_token=ACCESS_TOKEN",
success: callback,
});
};
interpreter.setProperty(scope, 'getSensorValue',
interpreter.createAsyncFunction(wrapper));You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/W8r5p5qcqKM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So the JS-interpreter is going to call the wrapper function, not the other function you created. At this point you'll need to debug the wrapper function until it does what you want. You can try calling it with a callback and logging the result directly:var callback = function(result) {console.log(result);}wrapper(callback);Or you can add console logs into the wrapper function directly. When you're using the interpreter the wrapper function is being mapped to the name you passed to interpreter.setProperty and any other functions outside the interpreter's scope won't exist.
To unsubscribe from this group and all its topics, send an email to blo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Pratika,
The Async demo from the JS-Interpreter is a complete demo showing all of those things. I'm sorry, but we're not able to provide you complete working code for your specific case.
Hi Pratika,
The Async demo from the JS-Interpreter is a complete demo showing all of those things. I'm sorry, but we're not able to provide you complete working code for your specific case.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anytime you're wrapping a function that takes more than a few ms you should use a callback and wrap it as an AsyncFunction.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.