As part of pulumi/pulumi-fabric#331, we've been exploring just using undefined to indicate that a property value is absent during planning. We also considered blocking the message loop to simplify the overall programming model, so that all asynchrony is hidden. It turns out ThereBeDragons 🐲 anytime you try to block the message loop. So, we aren't quite sure about that bit. But the part we are convicted about is that this Computed/Property model is far too complex. Furthermore, it's very close to promises, and yet frustratingly so far away. Indeed, the original thinking in pulumi/pulumi-fabric#271 was simply to use promises, but we wanted to encourage dataflow styles, rather than control flow. But we muddied up our thinking by worrying about awaiting a promise that would never resolve. It turns out we can achieve a middle ground: resolve planning promises to undefined, so that they don't lead to hangs, but still use promises so that asynchrony is explicit in the system. This also avoids blocking the message loop. Who knows, this may actually be a fine final destination.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
import { Property, PropertyValue } from "../resource";
|
|
|
|
// Asset represents a blob of text or data that is managed as a first class entity.
|
|
export abstract class Asset {
|
|
}
|
|
|
|
// Blob is a kind of asset produced from an in-memory blob represented as a byte array.
|
|
/* IDEA: enable this once Uint8Array is supported.
|
|
export class Blob extends Asset {
|
|
constructor(data: Uint8Array) {
|
|
super();
|
|
}
|
|
}
|
|
*/
|
|
|
|
// FileAsset is a kind of asset produced from a given path to a file on the local filesystem.
|
|
export class FileAsset extends Asset {
|
|
public readonly path: Property<string>; // the path to the asset file.
|
|
|
|
constructor(path: PropertyValue<string>) {
|
|
super();
|
|
this.path = Promise.resolve<string | undefined>(path);
|
|
}
|
|
}
|
|
|
|
// StringAsset is a kind of asset produced from an in-memory UTF8-encoded string.
|
|
export class StringAsset extends Asset {
|
|
public readonly text: Property<string>; // the string contents.
|
|
|
|
constructor(text: PropertyValue<string>) {
|
|
super();
|
|
this.text = Promise.resolve<string | undefined>(text);
|
|
}
|
|
}
|
|
|
|
// RemoteAsset is a kind of asset produced from a given URI string. The URI's scheme dictates the protocol for fetching
|
|
// contents: `file://` specifies a local file, `http://` and `https://` specify HTTP and HTTPS, respectively. Note that
|
|
// specific providers may recognize alternative schemes; this is merely the base-most set that all providers support.
|
|
export class RemoteAsset extends Asset {
|
|
public readonly uri: Property<string>; // the URI where the asset lives.
|
|
|
|
constructor(uri: PropertyValue<string>) {
|
|
super();
|
|
this.uri = Promise.resolve<string | undefined>(uri);
|
|
}
|
|
}
|
|
|