Close popup automatically after x seconds in Perspective

I don't like to use sleep() either. The code is inspired from this answer from @cmallonee on another post.

Thank you @Transistor and @josborn for the proposed alternative.

The finally working setup of the view's custom properties is:

  • viewOpenedAt
    • Binding: now(0)
    • Persistant: false
  • viewTimeout
    • Binding: (now() - {this.custom.viewOpenedAt}) > 30000
    • Change Script:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value == True:
		system.perspective.closePopup("")

A working view example:

{
  "custom": {},
  "params": {},
  "propConfig": {
    "custom.viewOpenedAt": {
      "binding": {
        "config": {
          "expression": "now(0)"
        },
        "type": "expr"
      },
      "persistent": false
    },
    "custom.viewTimeout": {
      "binding": {
        "config": {
          "expression": "(now() - {this.custom.viewOpenedAt}) \u003e 30000"
        },
        "type": "expr"
      },
      "onChange": {
        "enabled": null,
        "script": "\tif currentValue.value \u003d\u003d True:\n\t\tsystem.perspective.closePopup(\"\")"
      },
      "persistent": false
    }
  },
  "props": {},
  "root": {
    "children": [
      {
        "meta": {
          "name": "Label"
        },
        "position": {
          "basis": "32px"
        },
        "props": {
          "text": "This popup will close automatically in 30s",
          "textStyle": {
            "textAlign": "center"
          }
        },
        "type": "ia.display.label"
      },
      {
        "meta": {
          "name": "Label_0"
        },
        "position": {
          "basis": "32px"
        },
        "propConfig": {
          "props.text": {
            "binding": {
              "config": {
                "path": "view.custom.viewOpenedAt"
              },
              "transforms": [
                {
                  "expression": "\"viewOpenedAt: \" + {value}",
                  "type": "expression"
                }
              ],
              "type": "property"
            }
          }
        },
        "props": {
          "textStyle": {
            "textAlign": "center"
          }
        },
        "type": "ia.display.label"
      },
      {
        "meta": {
          "name": "Label_1"
        },
        "position": {
          "basis": "32px"
        },
        "propConfig": {
          "props.text": {
            "binding": {
              "config": {
                "path": "view.custom.viewTimeout"
              },
              "transforms": [
                {
                  "expression": "\"viewTimeout: \" + {value}",
                  "type": "expression"
                }
              ],
              "type": "property"
            }
          }
        },
        "props": {
          "textStyle": {
            "textAlign": "center"
          }
        },
        "type": "ia.display.label"
      }
    ],
    "meta": {
      "name": "root"
    },
    "props": {
      "direction": "column",
      "justify": "center"
    },
    "type": "ia.container.flex"
  }
}