My bad, Stig. I should have read that thoroughly. Rod is right. You're not 
supposed to convert the async functions.

Why not run an async function that fills a storage object and then run your 
unaltered sync code? Perhaps this:

>
((init) => {
    // run function.
    // waits for the init function to finish before running the script.
    init.then(([run, ...args]) => {
        run(...args)
    }).catch(e => {
        alert("Caught an error: " + e.toString())
    })
})
((async (main) => {
    // init function.
    // uses async GM API for initialization.
    // returns our sync API.
    var storage = {}

    // fetch async values and fill the storage
    await Promise.all([
        GM.getValue('gm4val', '').then(v => storage['gm4val'] = v),
        GM.getValue('foo', '').then(v => storage['foo'] = v),
        GM.getValue('bar', '').then(v => storage['bar'] = v),
    ]);


    // our sync API
    var gm4test = {
        INFO: true,
        DEBUG: false,
        log(s, info) {
            if ((info && window.console) || (gm4test.DEBUG && window.console
)) {
                window.console.log('*GM4test* '+s);
            }
        },
        getValue(name, defval) {
            var rt = name in storage ? storage[name] : defval;
            return rt;
        },
        setValue(name, value) {
            storage[name] = value
            GM.setValue(name, value).catch(e => gm4test(`Couldn't set 
value: ${name} ${value}`))
        }
    };


    return [main, gm4test];
})
((gm4test) => {
    // ==UserScript==
    // @name        GM4 API test
    // @namespace   dk.rockland.userscript.gm4apitest
    // @description Testing cross-API getValue and setValue
    // @version     2017.10.08.0
    // @author      Stig Nygaard, http://www.rockland.dk
    // @match       *://*.greasespot.net/*
    // @grant       GM.getValue
    // @grant       GM.setValue
    // @grant       GM_getValue
    // @grant       GM_setValue
    // ==/UserScript==


    gm4test.log('Running...');


    // Set...
    gm4test.setValue('gm4val', 42);
    // and get again...
    var rv = gm4test.getValue('gm4val', '');


    alert('value='+rv); // Expected "value=42"
}));

It sounds like you're going to have to choose a GM API flavor and rewrite 
your user scripts.

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to