a93febb5b7
* add image and deprecated arrow functions * update locales * map basic.showArrow * map arrow blocks * map & remove arrow images * remove arrow blocks * update locales * remove & patch: rgbw -> rgb button/pin pressed -> button/pin event loudness -> soundLevel * update ts mappings for arrows * add wip ts patch rules * update .blocks files * use Click instead of Down as default in Documentation and tests * patch test.blocks * fix lowercase name tag * update test.blocks * update blocks test files * update blocks test files * format block files * pass blocks file tests * fix ts mapping * fix color.defl value closes https://github.com/microsoft/pxt-calliope/issues/136 * fix ts mappings - add optional spacing at the end of rgbw() - map up to v4.0.19 * add suggested changes * replace innerText by textContent Co-authored-by: JW <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
55 lines
1022 B
Markdown
55 lines
1022 B
Markdown
# Run In Background
|
|
|
|
Run part of a program while the rest of it is doing something else.
|
|
|
|
```sig
|
|
control.inBackground(() => {
|
|
})
|
|
```
|
|
|
|
## ~hint
|
|
|
|
For more information, read
|
|
[The @boardname@ - a reactive system](/device/reactive).
|
|
It is pretty advanced!
|
|
|
|
## ~
|
|
|
|
## Example
|
|
|
|
This program shows how running in the background can say what is
|
|
stored in a variable like `num`, while another part (``on button pressed``)
|
|
changes what is stored there.
|
|
|
|
```blocks
|
|
let num = 0
|
|
control.inBackground(() => {
|
|
while (true) {
|
|
basic.showNumber(num)
|
|
basic.pause(100)
|
|
}
|
|
})
|
|
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
|
num++;
|
|
})
|
|
```
|
|
|
|
This program does the same thing, but in a more usual way,
|
|
with a ``forever`` loop.
|
|
|
|
```blocks
|
|
let num = 0
|
|
basic.forever(() => {
|
|
basic.showNumber(num)
|
|
})
|
|
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
|
num++;
|
|
})
|
|
```
|
|
|
|
## See also
|
|
|
|
[while](/blocks/loops/while), [forever](/reference/basic/forever),
|
|
[on button pressed](/reference/input/on-button-pressed)
|
|
|