github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/dotnet/gen_intrinsics.go (about)

     1  // Copyright 2016-2020, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package dotnet
    16  
    17  import (
    18  	"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/model"
    19  )
    20  
    21  const (
    22  	// intrinsicAwait is the name of the intrinsic to await tasks.
    23  	intrinsicAwait = "__await"
    24  	// intrinsicOutput is the name of the intrinsic to convert tasks to Pulumi outputs.
    25  	intrinsicOutput = "__output"
    26  )
    27  
    28  // newAwaitCall creates a new call to the await intrinsic.
    29  func newAwaitCall(promise model.Expression) model.Expression {
    30  	// TODO(pdg): unions
    31  	promiseType, ok := promise.Type().(*model.PromiseType)
    32  	if !ok {
    33  		return promise
    34  	}
    35  
    36  	return &model.FunctionCallExpression{
    37  		Name: intrinsicAwait,
    38  		Signature: model.StaticFunctionSignature{
    39  			Parameters: []model.Parameter{{
    40  				Name: "promise",
    41  				Type: promiseType,
    42  			}},
    43  			ReturnType: promiseType.ElementType,
    44  		},
    45  		Args: []model.Expression{promise},
    46  	}
    47  }
    48  
    49  // newOutputCall creates a new call to the output intrinsic.
    50  func newOutputCall(promise model.Expression) model.Expression {
    51  	promiseType, ok := promise.Type().(*model.PromiseType)
    52  	if !ok {
    53  		return promise
    54  	}
    55  
    56  	return &model.FunctionCallExpression{
    57  		Name: intrinsicOutput,
    58  		Signature: model.StaticFunctionSignature{
    59  			Parameters: []model.Parameter{{
    60  				Name: "promise",
    61  				Type: promiseType,
    62  			}},
    63  			ReturnType: model.NewOutputType(promiseType.ElementType),
    64  		},
    65  		Args: []model.Expression{promise},
    66  	}
    67  }