Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [gelöst/Pebcak] Problem mit Klasse/Zugriff auf variable

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    2.2k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    944

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.2k

[gelöst/Pebcak] Problem mit Klasse/Zugriff auf variable

Geplant Angeheftet Gesperrt Verschoben JavaScript
2 Beiträge 1 Kommentatoren 199 Aufrufe 1 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • Great SUNG Offline
    Great SUNG Offline
    Great SUN
    schrieb am zuletzt editiert von Great SUN
    #1

    Hi Ihr, ich verstehe etwas nicht... Vielleicht kann mir das jemand erklären, oder mir evtl. auch bei einer Lösung für das Problem, das ich mit der Klasse versuche zu lösen helfen...

    Das zu erreichende Ziel ist, dass ich eine Anzahl (sagen wir 8) URLs abfragen möchte und wenn mind. 4 davon erfolgreich abgefragt wurden, möchte ich einen zweiten callBack auslösen, der mir dann im callBack2Dict hinterlegte Schalter "umlegt".

    class runParallelHttpAndSetGroupSwitch {
        constructor(urlListObj, options, callBack, callBack2, callBack2Dict) {
            this.urlListObj = urlListObj;
            this.options = options;
            this.callBack = callBack;
            this.callBack2 = callBack2;
            this.callBack2Dict = callBack2Dict;
            this.neededAmount = Math.round(this.urlListObj.length / 2);
            this.callBack2Executed = false;
            this.returnCount = 0;
        }
        execHttpRequest(urlListKey) {
            var request = require('then-request');
            request('GET', this.urlListObj[urlListKey], this.options).getBody('utf-8').done((resBody) => {
                this.returnCount += 1;
                if(this.neededAmount > 0) {
                    this.neededAmount -= 1;
                }
                if (this.callBack2Executed === false && this.neededAmount == 0) {
                    logStr('Achieved! -> calling callBack2 with ' + JSON.stringify(this.callBack2Dict));
                    this.callBack2Executed = true;
                    this.callBack2(this.callBack2Dict);
                }
                var logConfArr = [urlListKey, ' -> parralel request result', this.returnCount, '(', this.neededAmount, ') cb2exec: ', this.callBack2Executed, ' -> @@result@@'];
                this.callBack(resBody, logConfArr);
            })
        }
        execute() {
            var promiseArr = [];
            Object.keys(this.urlListObj).map((urlListKey) => {
                promiseArr.push(this.execHttpRequest(urlListKey));
            });
            try {
                Promise.all(promiseArr).catch(function (error) {
                    logStr('Error-catch1 while executing parallel requests: ' + JSON.stringify(this.urlListObj) + ': ' + error);
                });
            } catch (error) {
                var errMsg = 'Error-catch2 while trying to execute parallel requests: ' + JSON.stringify(this.urlListObj) + ': ' + error;
                logStr(errMsg, 'warn');
            }
        }
    }
    
    async function execParallelHttpRequests(urlListObj, overrideOptions, noMerge, callBack, callBack2, callBack2Dict) {
        var options = { 'retry': true, 'retryDelay': 150, 'maxRetries': 10 };
        options = mergeOptionDict(options, overrideOptions, noMerge);
        var parReqGroupSwitch = new runParallelHttpAndSetGroupSwitch(urlListObj, options, callBack, callBack2, callBack2Dict);
        parReqGroupSwitch.execute();
    }
    

    Bei einer Ausgabe des logConfArr kommt dann folgendes heraus:

    console.log(logConfArr.join())
    
    ->
    
    <request url> parralel request result1(NaN) cb2exec: false -> <request result>
    

    Wieso gibt this.returnCount einen Wert aus, aber this.neededAmount ist NaN?!?

    Danke für Eure Unterstützung!

    P.S.: Kann sein, dass ich das mittlerweile schon wieder total verhunzt hab, aber ich bastel da jetzt schon ne Weile dran herum und ich weiß nicht mehr, was ich noch ändern soll...

    1 Antwort Letzte Antwort
    0
    • Great SUNG Offline
      Great SUNG Offline
      Great SUN
      schrieb am zuletzt editiert von
      #2

      Oh man... wie doof muss man sein...
      Ein Dictionary und ich mach .length drauf...

      this.neededAmount = Math.round(Object.keys(this.urlListObj).length / 2);
      

      so gehört das!

      1 Antwort Letzte Antwort
      0
      Antworten
      • In einem neuen Thema antworten
      Anmelden zum Antworten
      • Älteste zuerst
      • Neuste zuerst
      • Meiste Stimmen


      Support us

      ioBroker
      Community Adapters
      Donate

      330

      Online

      32.6k

      Benutzer

      82.2k

      Themen

      1.3m

      Beiträge
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
      ioBroker Community 2014-2025
      logo
      • Anmelden

      • Du hast noch kein Konto? Registrieren

      • Anmelden oder registrieren, um zu suchen
      • Erster Beitrag
        Letzter Beitrag
      0
      • Home
      • Aktuell
      • Tags
      • Ungelesen 0
      • Kategorien
      • Unreplied
      • Beliebt
      • GitHub
      • Docu
      • Hilfe